OpenForm Where condition question

G

Guest

I am trying to open a form to a certain record based on criteria but I keep
getting a run-time error 75, syntax error. First of here is my code

Private Sub xTree_DblClick()
' Allow Users to Open the Form selected record.

Dim strKey As String
strKey = Me.xTree.SelectedItem
DoCmd.OpenForm "NewMaintenanceWorkOrder", , , ("[WOKeyInfo]=" &
strKey)
End Sub

Now the text it is receiving is like this..ie
(Work Order #1), (Problem) - Machine Crash

When it errors it says "Syntax error (missing operator) in query expression
'[WOKeyInfo]=(Work Order #1), (Problem) - Machine Crash'.

I thought maybe it was a problem reading the selecteditem, so I put an
unbound box in the form and set the xTree.Click() to set the value from the
selecteditem into the unbound box and the dblClick() to read from it ..ie

DoCmd.OpenForm "NewMaintenanceWorkOrder", , , ("[WOKeyInfo]=" & [Text1])

Same Error, but if I input the text directly into the code ..ie
DoCmd.OpenForm "NewMaintenanceWorkOrder", , , ("[WOKeyInfo]= '(Work Order
#1), (Problem) - Machine Crash)'")

it works. My Question is why, is it the parenthesis or the comma causing
the problem or is it a problem with my expression.
 
G

Guest

from Hong Kong Rainbow01

if [WOKeyInfo] is string (text type), u need add ' between your criteria

i.e. "[WOKeyInfo]= ' " & Criteria & " ' "


"default105" 來函:
 

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

Top