Results 1 to 7 of 7
  1. #1
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87

    Error message for Form Search Code

    I am using the following code to do a search within my main data entry form:

    Private Sub cboOrderSearch_AfterUpdate()
    Me.RecordsetClone.FindFirst "[OrderID] = " & Me!cboOrderSearch
    Me.Bookmark = Me.RecordsetClone.Bookmark
    End Sub

    The issue I am running into is when I delete the search criteria I get the following message:

    Run-time error '3077':



    Syntax error (missing operator) in expression.

    It doesn't affect use of the form but is a little annoying. Any help would be appreciated. TIA

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    don't use Find First, instead filter ALL records to be the correct value,then let the user look thru them:

    Code:
    sub cboBox_Afterupdate()
    If IsNull(cboBox) Then
      Me.FilterOn = False
    Else
      Me.Filter = "[CCode]='" & cboBox & "'"
      Me.FilterOn = True
    End If
    end sub

  3. #3
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    Thank you for the quick response. I will try that.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Use conditional code:

    If Me.cboOrderSearch & "" <> "" Then

    Use dot . instead of bang ! to trigger intellisense popup tips.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    Quote Originally Posted by ranman256 View Post
    Me.Filter = "[CCode]='" & cboBox & "'"
    [/code]
    I entered the code but now receiving the following error:
    Run-time error'3075':
    Syntax error in string in query expression '[CCode]='728'.

    I'm not very proficient at code so please excuse me if I seem a little dumb about this. What is the [CCode] referencing? TIA

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    If you use Ranman's code, replace cboBox and CCode with actual names from your db: cboSearchOrder and OrderID.

    Did you see post 4?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    Thanks for the clarification June7. I actually hadn't seen Post 4. I was probably typing up post at the same time. Replacing the CCode with OrderID solved the issue. Thank you both for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-15-2018, 09:46 AM
  2. Replies: 3
    Last Post: 10-23-2017, 02:09 PM
  3. VBA code for form to display Error message
    By CTVT in forum Programming
    Replies: 9
    Last Post: 12-11-2015, 09:53 PM
  4. Code for search form error
    By jfn15 in forum Forms
    Replies: 4
    Last Post: 06-11-2013, 09:02 AM
  5. Replies: 7
    Last Post: 09-21-2012, 03:30 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