ekendricks
Posts: 34
|
| Posted: 07/17/2005, 5:34 PM |
|
I tried to follow the Store example in doing custom insert - update - delete. So far I've not been successful on the first phase - insert.
Using Access 2K CCS
I get error : Operation Not Allowed when the Object is closed:
Function Employees_AfterInsert() 'Employees_AfterInsert @2-B41D0C45
'Custom Code @100-73254650
' -------------------------
Dim Sql
Dim RecordSet
Dim EmpID
'Get EmpID From Table "Employees"
'This method compatible with all databases (unsafe when multiple users insert records at the same time)
'Use your own method for your database.
SQL = "SELECT MAX(EmpID) FROM Employees"
Set RecordSet = DBMed.Execute(SQL)
EmpID = CCGetValue(RecordSet, 0)
'Add Record to table ezUser
SQL = "SELECT EmpID, UserName, Pswd, Email, PhoneHome, Admin" _
& "FROM Employees " _
& "WHERE EmpID = " & DBMed.ToSQL(Request.Cookies("EmpID"),ccsInteger)
Set RecordSet = DBMed.Execute(SQL)
While NOT Recordset.EOF
SQL = "INSERT INTO ezUser (EmployeeID, UserID, Password, Email, Phone, Admin ) " _
& "VALUES (" & DBMed.ToSQL(EmpID,ccsInteger) _
& "," & DBMed.ToSQL(CCGetValue(RecordSet, "UserName"),ccsText) _
& "," & DBMed.ToSQL(CCGetValue(RecordSet, "Pswd"),ccsText) _
& "," & DBMed.ToSQL(CCGetValue(RecordSet, "Email"),ccsText) _
& "," & DBMed.ToSQL(CCGetValue(RecordSet, "PhoneHome"),ccsText) _
& "," & DBMed.ToSQL(CCGetValue(RecordSet, "Admin"),ccsBoolen) _
& ")"
DBMed.Execute(SQL)
Recordset.MoveNext
Wend
' -------------------------
'End Custom Code
If someone would be so kind as to tell me what I've done wrong, I would greatly appreciate it. Hopefully the update - delete function won't be as bad.
Thanks
|
 |
 |
smalloy
Posts: 107
|
| Posted: 07/18/2005, 6:32 AM |
|
It looks like you never instantiate the database object.
Put this code before your code:
'Declare Variables
Dim DBMed
'Open the database
Set DBMed = New clsDBMed
DBMed.Open
And this After:
'Clean Up
If DBMed .State = adStateOpen Then _
DBMed .Close
Set DBMed = Nothing
You should be fine!
_________________
Anything can be done, just give me time and money. |
 |
 |
|