Syntax error message when opening Subform

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
 
M

Marshall Barton

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top