Syntax error message when opening Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a command button on my mainform that when clicked should open my
subform (Form2), with the current record (ID). The ID control is in both my
main form and subform, however I keep on getting the following error message:
"Syntax error (missing operator) in query expression 'ID='." Can anyone
figure out what is wrong with my code?
Thanks!

---------------------------
Private Sub Change_Imp_Date_Click()
On Error GoTo Err_Change_Imp_Date_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Change_Imp_Date_Click:
Exit Sub

Err_Change_Imp_Date_Click:
MsgBox Err.Description
Resume Exit_Change_Imp_Date_Click

End Sub
 
jojo said:
I have a command button on my mainform that when clicked should open my
subform (Form2), with the current record (ID). The ID control is in both my
main form and subform, however I keep on getting the following error message:
"Syntax error (missing operator) in query expression 'ID='."
--------------------------- []

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
[]

The way you're code using it, form2 is not a subform, it is
a separate form. A subform is a dorm imbedded ina subform
control on the main form.

As far as the code goes, you'd get that message if the ID
control did not have a value when the button was clicked,
 
Back
Top