Hi,
I was wondering if anyone can help me.
I have a main form with a combo box (it shows Users LastName) runing on a query. Here is the code:
---------------------------------------------
SELECT DISTINCTROW Users.UserID,Users.LastName FROM Users ORDER BY Users.LastName;
---------------------------------------------
Additionaly on the same (main) form I have a button, which opens the subform 'Users' so I can edit the LastName of the 'user'. Here is the code (in on Click event) for the button:
---------------------------------------------
Private Sub CmdUser_Click()
On Error GoTo Err_CmdUser_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Users"
stLinkCriteria = "[UserID]=" & Me![UserID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_CmdUser_Click:
Exit Sub
Err_CmdUser_Click:
MsgBox Err.Description
Resume Exit_CmdUser_Click
End Sub
-------------------------------------------
It works fine for existing 'user' but I have a problem adding new 'user' in a certain situation:
Let imagine I have to add a new record on the main form and the combo box field is empty (O.K.). Now I have to put a 'user' Lastname for that new record. I don't now if the 'user' is in my database or not, so I go to the combo box and start typing the 'Lastname' in the combo box field.
The name is not on the list so I delete what I have typed and try to open the subform 'Users' (button) to add a NEW 'user' Lastname, but the button is locked and I get msgbox:
"Syntax error (missing operator) in query expression '[UserID]=' ".
Thanks for any advice,
E.
I was wondering if anyone can help me.
I have a main form with a combo box (it shows Users LastName) runing on a query. Here is the code:
---------------------------------------------
SELECT DISTINCTROW Users.UserID,Users.LastName FROM Users ORDER BY Users.LastName;
---------------------------------------------
Additionaly on the same (main) form I have a button, which opens the subform 'Users' so I can edit the LastName of the 'user'. Here is the code (in on Click event) for the button:
---------------------------------------------
Private Sub CmdUser_Click()
On Error GoTo Err_CmdUser_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Users"
stLinkCriteria = "[UserID]=" & Me![UserID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_CmdUser_Click:
Exit Sub
Err_CmdUser_Click:
MsgBox Err.Description
Resume Exit_CmdUser_Click
End Sub
-------------------------------------------
It works fine for existing 'user' but I have a problem adding new 'user' in a certain situation:
Let imagine I have to add a new record on the main form and the combo box field is empty (O.K.). Now I have to put a 'user' Lastname for that new record. I don't now if the 'user' is in my database or not, so I go to the combo box and start typing the 'Lastname' in the combo box field.
The name is not on the list so I delete what I have typed and try to open the subform 'Users' (button) to add a NEW 'user' Lastname, but the button is locked and I get msgbox:
"Syntax error (missing operator) in query expression '[UserID]=' ".
Thanks for any advice,
E.