Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91

    End of Statement Error Message

    I am getting an end of statement error msg.



    Click image for larger version. 

Name:	Capture5.JPG 
Views:	22 
Size:	61.8 KB 
ID:	36232

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The opening quotes in your Forms(...) closes the quotes for the string you're building, leaving everything after twisting in the wind. Use single quotes there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    The opening quotes in your Forms(...) closes the quotes for the string you're building, leaving everything after twisting in the wind. Use single quotes there.
    I get expression error now when I change it to single quotes, I tried the following
    1. Forms('...') and Forms('...')
    2. Forms('...') and Forms("...")
    3. Forms("...") and Forms('...')

    Code:
        If Forms('002_Criteria').CKNFixer.ControlSource = True Then        strFilterString = strFilterString & " OR Forms('002_Criteria').NFixer = True"
        End If

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    CKNFixer.ControlSource = True
    This doesnt look right to me. Is the name of the field True?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Good catch Moke, I didn't see that.

    How about this, though it seems odd to refer to a form in the criteria like that.

    strFilterString = strFilterString & " OR Forms!002_Criteria.NFixer = True"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    This is what I have written, but nothing is filtering out at all in the List Box.

    Code:
    Private Sub Refilter()    
        Dim strFilterString As String
    
    
        'BUILD THE FILTER STRING:
        If Forms("002_Criteria").CKNFixer.ControlSource = True Then
            strFilterString = strFilterString & " OR Forms!002_Criteria.NFixer = True"
        End If
        
        'REMOVE LEADING " OR " ON FILTER STRING:
        If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
        
        'APPLY FILTER STRING TO 003_Species:
        If strFilterString <> "" Then
            Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
        Else
            Forms("003_Species").ListSciName.RowSource = "qSciName"
        End If
    
    
    End Sub

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you see Moke's post 4? Also, in words what are you trying to accomplish? Saying "where a form control is true" doesn't make any sense from a data perspective. I'd expect "where a field is true" or something similar.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    Did you see Moke's post 4? Also, in words what are you trying to accomplish? Saying "where a form control is true" doesn't make any sense from a data perspective. I'd expect "where a field is true" or something similar.
    I have a list box that displays all species on Form 003_Species. On 002_Criteria Form there are check boxes, if NFixer is one of the check box. If selected it is only going to show the species = Yes on Form 003_Species.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Then I'd expect:

    strFilterString = strFilterString & " OR Species = True"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    Then I'd expect:

    strFilterString = strFilterString & " OR Species = True"
    IT still does nothing, I even type it as Forms!003_Species.ListSciName, and gives me invalid character expression. With it type like this Forms("003_Species").ListSciName, the debug locates the correct part of the form.


    Code:
    Private Sub Refilter()    
        Dim strFilterString As String
    
    
        'BUILD THE FILTER STRING:
        If Forms("002_Criteria").CKNFixer.ControlSource = True Then
            strFilterString = strFilterString & " OR Forms!003_Species.ListSciName = True"
        End If
        
        'REMOVE LEADING " OR " ON FILTER STRING:
        If strFilterString <> "" Then strFilterString = Mid(strFilterString, 5)
        
        'APPLY FILTER STRING TO 003_Species:
        If strFilterString <> "" Then
            Forms("003_Species").ListSciName.RowSource = "SELECT * FROM [qSciName] WHERE " & strFilterString
        Else
            Forms("003_Species").ListSciName.RowSource = "qSciName"
        End If
    
    
    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It needs to be the name of a field in the record source (table), not a form reference. Basically:


    strFilterString = strFilterString & " OR FieldName = True"

    If you're saying the listbox contains a field name, you have to concatenate that in so it results in the above:

    strFilterString = strFilterString & " OR " & Forms!003_Species.ListSciName & " = True"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    It needs to be the name of a field in the record source (table), not a form reference. Basically:


    strFilterString = strFilterString & " OR FieldName = True"

    If you're saying the listbox contains a field name, you have to concatenate that in so it results in the above:

    strFilterString = strFilterString & " OR " & Forms!003_Species.ListSciName & " = True"
    The field name with yes/no values is NFixer, I was confused when told to change that. It still gives me the invalid expression written as Forms!002_criteria.nfixer

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How about:

    strFilterString = strFilterString & " OR NFixer = True"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    How about:

    strFilterString = strFilterString & " OR NFixer = True"
    I am totally lost, just writing NFixer doesn't.

    I even put added the fields in the query. As soon as I add in the other Fields to correspond with the check box, it cause the scientific names to shrink in the list box until nothing is showing. It is just reading from the query, as I deleted the code to see if the results differ and it did not. It's not reading the code at from the vba.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It's not reading the code at from the vba
    PMFJI but maybe the code isn't executing as expected. I suggest stepping through to see what happens, and check the variables to see if their values make sense. The focus seems to be on the filter string, but this CKNFixer.ControlSource = True makes no sense to me so the IF block might be bypassed. Maybe it should be
    If Forms("002_Criteria").CKNFixer= True Then
    or
    If Forms!002_Criteria.CKNFixer= True Then
    Last edited by Micron; 11-19-2018 at 08:43 PM. Reason: line wraps
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2016, 05:53 PM
  2. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  3. macrohelp needed - error message if statement
    By dcorleto in forum Queries
    Replies: 8
    Last Post: 07-22-2013, 12:44 PM
  4. Replies: 2
    Last Post: 04-04-2013, 03:13 PM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums