Need help coding a search box (1 Viewer)

gojets1721

Registered User.
Local time
Today, 09:47
Joined
Jun 11, 2019
Messages
430
I have a search command button that I'm hoping will allow the user to input a name and it filters all the entries down to that name. I also want it to automatically filter to only the last 18 months.

I came up with this rudimentary code and it doesn't work. I'm very green to VBA. Any suggestions?

Code:
Private Sub cmdSearch_Load()
  
    Dim S As String
    
    S = InputBox("Enter Customer Name", "Customer Name Search")
    If S = "" Then Exit Sub
    
    Me.Filter = "CustomerName LIKE ""*" & S & "*""" And ComplaintDate = DateAdd("m", -18, Date)
    Me.FilterOn = True
  
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:47
Joined
Oct 29, 2018
Messages
21,497
Maybe?
Code:
Me.Filter = "CustomerName Like ""*" & S & "*"" AND ComplainDate >= DateAdd(""m"", -18, Date())"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:47
Joined
May 7, 2009
Messages
19,247
you may also try:

Me.Filter = "CustomerName LIKE '*" & S & "*' And ComplaintDate = " & Format(DateAdd("m", -18, Date), "\#mm\/dd\/yyyy\#")
 

Users who are viewing this thread

Top Bottom