Enter Parameter Value?

B

Bob Richardson

Here's coding of an OnClick event for an "Add Event" button. The idea was to
add the record, then open a form which will allow entering of all other
fields. The OpenForm event has some sort of syntax error. After entering a
new code, e.g. ag01, I get a dialog box with the above error message. If I
reenter the code, it looks like everything works correctly; however, it's
silly to have to enter the code twice. What have I done wrong. The primary
key to the Events file is EvCode.


Code = InputBox$("Enter New Event Code...usually formatted AAnn", "XX99")

If Code = "" Then
Exit Sub
End If

Code = UCase$(Code)
rs.AddNew
rs.Fields("EvCode") = Cstr(Code)
rs.Fields("EventName") = "This must be entered"
rs.Update
DoCmd.OpenForm "EventForm", , , "[Events.EvCode]=" & Code
 
D

Douglas J Steele

Since EvCode is a text field, whatever you're comparing it to must be in
quotes:

DoCmd.OpenForm "EventForm", , , "[Events.EvCode]='" & Code & "'"

Exagerated for clarity, that's


DoCmd.OpenForm "EventForm", , , "[Events.EvCode]=' " & Code & " ' "

Alternatively, you could use

DoCmd.OpenForm "EventForm", , , "[Events.EvCode]=" & Chr$(34) & Code &
Chr$(34)

or

DoCmd.OpenForm "EventForm", , , "[Events.EvCode]=""" & Code & """"

(that's 3 double quotes in a row before & Code &, and 4 double quotes in a
row after)
 
Top