Results 1 to 6 of 6
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Use a inputbox to search and filter a numeric field?

    I've got a DB of complaints and a form that looks at each complaint one by one. I'd like to include a button next to the ComplaintNumber of each complaint that allows the user to search for a specific complaint number if they wanted to.

    I found this great tutorial online that I used to allow the user to search the customer last name field, but it doesn't work for numeric fields and my ComplaintNumber field is a number field. I'm not sure what needs to be changed and I can't find any other tutorials. Any idea what needs to be altered? Here's my code:

    Code:
    Private Sub btnSearchComplaintNumber_Click()    
        Dim S As String
        
        S = InputBox("Enter the ComplaintNumber", "ComplaintNumber Search")
        If S = "" Then Exit Sub
        
        Me.Filter = "ComplaintNumber = """ & S & """"
        Me.FilterOn = True
        
    End Sub


  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    For a number field use

    Code:
    Private Sub btnSearchComplaintNumber_Click()        
    
        Dim S As Long
        
        S = InputBox("Enter the ComplaintNumber", "ComplaintNumber Search")
        If IsNull(S) Then Exit Sub
    
        Me.Filter = "CustomerID = " & S
        Me.FilterOn=True
    
     End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    a form that looks at each complaint one by one. I'd like to include a button next to the ComplaintNumber
    Then why do you use an InputBox to get the complaint number if it's right there on the form?

    Posted code will filter that form to a complaint number, but is that what you really want as opposed to navigating to that record? Also, once applied, do you have code to undo the filter so that you can get the other records back? Consider double click event for the complaint number control. One dbl click to apply filter, another to remove it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Micron View Post
    Then why do you use an InputBox to get the complaint number if it's right there on the form?

    Posted code will filter that form to a complaint number, but is that what you really want as opposed to navigating to that record? Also, once applied, do you have code to undo the filter so that you can get the other records back? Consider double click event for the complaint number control. One dbl click to apply filter, another to remove it.
    Yes I do have a code for a button that removes the filter. But you bring up a good point. It may be better for the user if it just "goes to" the complaint number rather than filtering down to just that complaint number. Admittedly I have no idea how to do that lol. Do you know of any guides? I did a quick search but couldn't find any.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I like to use a variation of David W Fenton's code here
    https://stackoverflow.com/questions/...obox-in-access

    You'll need to tweak to suite your needs but the concept is there.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I would use the same approach as per kd107's link.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. 'InputBox' Field Size
    By BenPala in forum Access
    Replies: 1
    Last Post: 08-31-2014, 08:25 AM
  2. Replies: 3
    Last Post: 03-21-2014, 09:34 AM
  3. numeric field in table
    By msasan1367 in forum Access
    Replies: 13
    Last Post: 04-07-2013, 10:28 AM
  4. Create filter for multiple field search
    By luvsmel in forum Forms
    Replies: 5
    Last Post: 01-02-2012, 11:12 PM
  5. Linked file text/numeric filter performance
    By awc109 in forum Import/Export Data
    Replies: 0
    Last Post: 04-19-2011, 11:02 AM

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