Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003
    Location
    paris, FRANCE
    Posts
    88

    Unanswered: VB code on a form button

    Hello! I use Access 2002

    I found this code on the microsoft support site. I tried to use it with my own tables. So I changed the names of the reports and the tables they were refering to in a clean manner. This code is the code of an action button which takes the values from three comboboxes and filters the data shown on a report.

    When I try to use these filters, I get the correct values on the drop down list but when I push the go button, Access tells me I'm missing an operator, so I believe there's a syntax error somewhere.
    Apparently, this code stores the value chosen in my filters. Could someone explain to me quickly these code lines???

    here's an explanation but its still not clear to me...
    http://support.microsoft.com/default...b;en-us;208529

    Thx
    nico

    Code:
    Private Sub Command28_Click()
    
    Dim strSQL As String, intCounter As Integer
         'Build SQL String
         For intCounter = 1 To 3
           If Me("Filter" & intCounter) <> "" Then
             strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
           End If
         Next
    
         If strSQL <> "" Then
            'Strip Last " And "
            strSQL = left(strSQL, (Len(strSQL) - 3))
            'Set the Filter property
            Reports![rptCustomers].Filter = strSQL
            Reports![rptCustomers].FilterOn = True
         Else
            Reports![rptCustomers].FilterOn = False
         End If
    
    End Sub
    Last edited by nicolascaprais; 07-29-03 at 06:37.

  2. #2
    Join Date
    Jul 2003
    Posts
    48

    Re: VB code on a form button

    From looking at the code i can see that when removing the last And the count is 3. " AND " is actually 5 characters.

    Try sending the sql string to the screen (msgbox strSQL) after the string has been created, look for anything that looks incorrect. If you use debug.print strSQL in the code you can copy and past the sql created onto this forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •