Florida Doc
Weaksauce
- Joined
- Sep 9, 2004
- Messages
- 92
Hello,
I'm trying to write a subroutine that will update the usermodified field when a person clicks the save user button on a form. However, I keep getting the error: "Object variable or With block variable not set".
The table name is Users, the field I want to modify is UserModified, the field containing the username in the table is Username, and the form has a control called Username.
Here's my code:
Private Sub SaveChanges_Click()
On Error GoTo Err_SaveChanges_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Dim mySQL As String
Dim con As Object
con = Application.CurrentProject.Connection
MsgBox "Username to modify is " & Me![Username]
mySQL = "UPDATE [Users] SET [Users].[UserModified] =" & Now()
mySQL = mySQL & " WHERE [Users].[Username]=" & Me![Username]
MsgBox "SQL command is:" & mySQL
DoCmd.SetWarnings True
DoCmd.RunSQL mySQL
'Close the connection
Set con = Nothing
Exit_SaveChanges_Click:
Exit Sub
Err_SaveChanges_Click:
MsgBox Err.Description
Resume Exit_SaveChanges_Click
Any idea what's wrong?
Thanks!!!
I'm trying to write a subroutine that will update the usermodified field when a person clicks the save user button on a form. However, I keep getting the error: "Object variable or With block variable not set".
The table name is Users, the field I want to modify is UserModified, the field containing the username in the table is Username, and the form has a control called Username.
Here's my code:
Private Sub SaveChanges_Click()
On Error GoTo Err_SaveChanges_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Dim mySQL As String
Dim con As Object
con = Application.CurrentProject.Connection
MsgBox "Username to modify is " & Me![Username]
mySQL = "UPDATE [Users] SET [Users].[UserModified] =" & Now()
mySQL = mySQL & " WHERE [Users].[Username]=" & Me![Username]
MsgBox "SQL command is:" & mySQL
DoCmd.SetWarnings True
DoCmd.RunSQL mySQL
'Close the connection
Set con = Nothing
Exit_SaveChanges_Click:
Exit Sub
Err_SaveChanges_Click:
MsgBox Err.Description
Resume Exit_SaveChanges_Click
Any idea what's wrong?
Thanks!!!