How to clear up a specific error on search form (1 Viewer)

bigalpha

Registered User.
Local time
Today, 04:41
Joined
Jun 22, 2012
Messages
415
I have a search form that's slightly modified search form modeled after the one available here on this site. It's a main form with a list box. I use the listbox to narrow down the results I want from the search function.

The search details are shown in a sub form that contains sub-sub forms

As seen in the code below, I am using the listbox to set a filter on the subform . Works famously until I search for something that does not exist in the database. I then receive runtime error 3075.

I believe it's related to the way I'm showing the details in the subform (by enabling a filter). If there is no record in the database that match the search criteria, I don't want any error messages or pop-ups and preferably would like the listbox to be blank.

Attached a screenshot of my form.
red = main form
green = subform
blue = sub-subforms
tan = obscuring the search results

Code:
Private Sub SearchFor_Change()   
      Dim vSearchString As String
      vSearchString = SearchFor.Text
     
   SrchText.Value = vSearchString
   Me.SearchResults.Requery
      If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
          Exit Sub
      End If
      Me.SearchResults = Me.SearchResults.ItemData(1)
      Me.SearchResults.SetFocus
      
  [COLOR=Red]Me.frmInputWaste.Form.Filter = "[CurrentCYIDPK]= " & Forms!frmwastesearch.SearchResults[/COLOR]
[COLOR=Red]Forms!frmwastesearch.frmInputWaste.Form.FilterOn = True[/COLOR]


      DoCmd.Requery
      Me.SearchFor.SetFocus
   
      If Not IsNull(Len(Me.SearchFor)) Then
          Me.SearchFor.SelStart = Len(Me.SearchFor)
      End If
   
   
  End Sub
 

Attachments

  • SearchMain.jpg
    SearchMain.jpg
    98.3 KB · Views: 52
  • SearchMainError.JPG
    SearchMainError.JPG
    20.1 KB · Views: 62

pbaldy

Wino Moderator
Staff member
Local time
Today, 04:41
Joined
Aug 30, 2003
Messages
36,132
From the error it would appear the value isn't getting picked up. Have you tried:

Me.frmInputWaste.Form.Filter = "[CurrentCYIDPK]= " & Me.SearchResults
 

bigalpha

Registered User.
Local time
Today, 04:41
Joined
Jun 22, 2012
Messages
415
From the error it would appear the value isn't getting picked up. Have you tried:

Me.frmInputWaste.Form.Filter = "[CurrentCYIDPK]= " & Me.SearchResults

I only receive the error when I search for something that doesn't exist, otherwise, it functions normally.

So if I search for "test", I receive no error because I have a record with "test" in it.

If I search for "fat whale", I receive the error because "fat whale" doesn't show up anywhere in my search results.

edit: I changed my code to your suggestion and it did not change the behavior
 
Last edited:

Users who are viewing this thread

Top Bottom