Syntax error missing operator in query expression

wrightie

Registered User.
Local time
Today, 14:53
Joined
Jun 11, 2009
Messages
22
I have a form with a combo box for the name and an Ok button which runs the code below. The code works fine as long as the name doesn't have an apostrophe in it. If it does then I get this message Syntax error missing operator in query expression

Code:
Private Sub SearchForInfo_Click()
[FONT=Verdana][COLOR=black]On Error GoTo Err_SearchForInfo_Click[/COLOR][/FONT]
[COLOR=black][FONT=Verdana] Dim stDocName As String[/FONT][/COLOR]
[FONT=Verdana][COLOR=black] Dim stLinkCriteria As String[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black] stDocName = "Info"[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black] stLinkCriteria = "[Name]=" & "'" & Me![Name_ComboBox] & "'"[/COLOR][/FONT]
 
[COLOR=black][FONT=Verdana]DoCmd.OpenForm stDocName, , , stLinkCriteria[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Exit_SearchForInfo_Click:[/FONT][/COLOR]
[FONT=Verdana][COLOR=black] Exit Sub[/COLOR][/FONT]
[COLOR=black][FONT=Verdana]Err_SearchForInfo_Click:[/FONT][/COLOR]
[FONT=Verdana][COLOR=black] MsgBox Err.Description[/COLOR][/FONT]
[FONT=Verdana][COLOR=black] Resume Exit_SearchForInfo_Click[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=black]End Sub[/COLOR][/FONT]

I am sure this has got to be something simple. Any help is greatly appreciated.

wrightie
 
Try this:
StLinkCriteria = "[Name] = [Forms]![FormName]![FieldName]"
 
Ah hell what was I thinking ..... far too much by the looks of it! :o

Thanks so much MStef. Should of sorted it myself. Friday afternoon and the little old grey cells want to be in the pub.

cheers
wrightie
 
this cannot be correct, surely?

StLinkCriteria = "[Name] = [Forms]![FormName]![FieldName]

it must be something like

StLinkCriteria = "[Name] = " & chr(34) [Forms]![FormName]![FieldName] & chr(34)
 
this cannot be correct, surely?



it must be something like

StLinkCriteria = "[Name] = " & chr(34) [Forms]![FormName]![FieldName] & chr(34)

OR even better :D

StLinkCriteria = "[Name] = " & chr(34) & [Forms]![FormName]![FieldName] & chr(34)
 
i plead an oversight, m'lud

You're allowed ONE mistake and now that you've made it you have to be ultra careful. :D (if that was the case I'd be out of here a long time ago :) )
 

Users who are viewing this thread

Back
Top Bottom