Results 1 to 6 of 6
  1. #1
    mrmims is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    53

    VBA Programming for After Change() event?

    Hello,



    I have two unbound text boxes I use to search through Components by Part Number or Manufacturer. They both work perfect independently of each other, but I want to combine the search so if searching by Manufacturer doesn't narrow down far enough then typing a Part Number will filter based on what is already narrowed down from typing in a Manufacturer. Here is the VBA I am using. How do I combine these two???

    Code:
    Private Sub CompTxt_Change()
    
    
    Dim str1 As String
    
    
    str1 = "[PartNumber] LIKE '*" & Me.CompTxt.Text & "*'"
    
    
    Me!SUBFRM_Component_Datasheet.Form.Filter = str1
    Me!SUBFRM_Component_Datasheet.Form.FilterOn = True
    Me!SUBFRM_Inventory_Totals.Form.Filter = str1
    Me!SUBFRM_Inventory_Totals.Form.FilterOn = True
    
    
    End Sub
    
    
    Private Sub ManuTxt_Change()
    
    
    Dim str2 As String
    
    
    str2 = "[ManufacturerName] LIKE '*" & Me.ManuTxt.Text & "*'"
    
    
    Me!SUBFRM_Component_Datasheet.Form.Filter = str2
    Me!SUBFRM_Component_Datasheet.Form.FilterOn = True
    Me!SUBFRM_Inventory_Totals.Form.Filter = str2
    Me!SUBFRM_Inventory_Totals.Form.FilterOn = True
    
    
    End Sub
    Thank you for you help

  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
    Along the lines of:

    str1 = "[PartNumber] LIKE '*" & Me.CompTxt.Text & "*' AND [ManufacturerName] LIKE '*" & Me.ManuTxt.Text & "*'"

    But of course you can only use the .Text property in the change event of the control with focus. Personally I'd use the after update event, unless you want keystroke by keystroke results.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mrmims is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    53
    Thank you for the help!

    I do want the keystroke by keystroke feature. It is a small enough database, I am not worried about slowing down.

    I tried your suggestion, but get this error:

    Run Time Error '2185':

    You can't reference a property or method for a control unless the control has the focus.


    I am guessing because I am typing in CompTxt while referencing ManuTxt?

    Any other ideas?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Like I said, you can only use the Text property in the event of the control with focus. Don't use it referencing the other control.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    mrmims is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    53
    Ah, thank you

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 03-26-2014, 11:09 AM
  2. On Change event in Text Boc
    By quicova in forum Programming
    Replies: 2
    Last Post: 09-12-2013, 01:27 PM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. Programming to change Combobox to Textbox on the fly
    By shane201980 in forum Programming
    Replies: 3
    Last Post: 09-05-2012, 10:05 PM
  5. Any change of focus on form Event?
    By trb5016 in forum Forms
    Replies: 1
    Last Post: 02-11-2011, 08:25 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