Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Enter Parameter Value?

Discussion in 'Information Technology' started by Bob Richardson, Nov 12, 2005.

  1. Bob Richardson

    Bob Richardson
    Expand Collapse
    Guest

    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
     
  2. Loading...


  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    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)

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Bob Richardson" <bobr at whidbey dot com> wrote in message
    news:MI2dnRyKDO1umOjeRVn-iw@whidbeytel.com...
    > 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
    >
    >
     

Share This Page