none
VBA Run-time error '2471': The expression you entered as a query parameter produced this error RRS feed

  • Question

  • I have a form with the following fields: Week, Day, Work_Order, Operator, Reading_Number, Disc_Size, USL, LSL, Centre, Outer_Position_1, Outer_Position_2, Outer_Position_3, Outer_Position_4, Outer_Average.

    I want the code to get the last (Max) Reading_Number of a certain Disc_Size where Week equals the current week (the ISOWEEK gets this) and Day = 'Today's' day, when the Disc_Size field is changed.

    Here is the code:

    Private Sub Disc_Size_Change()
    Dim strCriteria As String
    Dim vCurrent_Day As String
    
    vCurrent_Day = WeekdayName(Weekday(Date), False, 1)
        strCriteria = "[Disc_Size]=" & Me![Disc_Size] & " AND " & "[Week]=" & ISOWEEK(Now(), 1) & " AND " & "[Day]=" & vCurrent_Day
        
        Me![Reading_Number] = Nz(DMax("Reading_Number", "Grinding_Control", strCriteria), 0) + 1

    This is the error I get: Run-time error '2471': The expression you entered as a query parameter produced this error: 'Thursday'

    At the line:

    Me![Reading_Number] = Nz(DMax("Reading_Number", "Grinding_Control", strCriteria), 0) + 1

    Thanks.



    Thursday, July 12, 2012 10:51 AM

Answers

  • Is the Day field a text field that contains day names such as Thursday? If so, the value of vCurrent_Day must be enclosed in quotes:

        strCriteria = "[Disc_Size]=" & Me![Disc_Size] & " AND [Week]=" & ISOWEEK(Now(), 1) & _
            " AND [Day]=" & Chr(34) & vCurrent_Day & Chr(34)

    Chr(34) is the double quote character ".

    Regards, Hans Vogelaar

    Thursday, July 12, 2012 11:32 AM

All replies

  • Is the Day field a text field that contains day names such as Thursday? If so, the value of vCurrent_Day must be enclosed in quotes:

        strCriteria = "[Disc_Size]=" & Me![Disc_Size] & " AND [Week]=" & ISOWEEK(Now(), 1) & _
            " AND [Day]=" & Chr(34) & vCurrent_Day & Chr(34)

    Chr(34) is the double quote character ".

    Regards, Hans Vogelaar

    Thursday, July 12, 2012 11:32 AM
  • Oh I see. That was a silly mistake.

    Thanks a million.

    Thursday, July 12, 2012 12:52 PM