Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37

    Find record based on text box

    Hello,
    This is what I want to accomplish: find a record in my form using a value from a text box(the value in text box comes from a main combo box).
    I know it is very easy to accomplish this using a combo box .
    I did some research but seems that this way requires some coding and I don't have much experience with it.
    I appreciate your help,


    Thank you

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by tazzzz View Post

    ...find a record in my form using a value from a text box(the value in text box comes from a main combo box).
    I know it is very easy to accomplish this using a combo box
    ...
    Why, if the data for the Textbox comes from an existing Combobox, don't you simply use the cbo to retrieve the Record?

    At any rate, the code/Macro in the AfterUpdate event of a Textbox, to do this, would be identical to that used in the AfterUpdate of a Combobox, to do this:

    Code:
    Private Sub ControlName_AfterUpdate()
      
     Dim rs As Object
    
     Set rs = Me.Recordset.Clone
       rs.FindFirst "[Field Name] = '" & Me!ControlName & "'"
     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    
    End Sub

    I vaguely seem to remember that in some versions of Access the line

    Set rs = Me.Recordset.Clone

    would have to be

    Set rs = Me.RecordsetClone

    without the dot between Recordset and Clone.

    Linq ;0)>

  3. #3
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    Thank you for your interest in this topic.
    I tried your code but something is off (no records are coming and no message of error).
    In the meantime I found this code. Is working only when data is input manually. When I reference the combo box the code stop working.
    Code:
    Option Compare Database
     
    Private Sub txtGoTo_AfterUpdate()
        If (txtGoTo & vbNullString) = vbNullString Then Exit Sub
        Dim rs As DAO.RecordSet
        Set rs = Me.RecordsetClone
       rs.FindFirst "[jobnumber]=""" & txtGoTo & """"
        If rs.NoMatch Then
            MsgBox "Sorry, no such record '" & txtGoTo & "' was found.", _
                   vbOKOnly + vbInformation
        Else
            Me.RecordSet.Bookmark = rs.Bookmark
        End If
        rs.Close
        txtGoTo = Null
    End Sub

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is jobnumber actually defined as a Number or as Text in the Table?

    For Text:

    rs.FindFirst "[jobnumber]= '" & txtGoTo & "'"

    For a Number:

    rs.FindFirst "[jobnumber]= " & txtGoTo

    Linq ;0)>

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    You might find this of interest http://www.allenbrowne.com/ser-62.html
    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.

  6. #6
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    Still not working. I attached a sample database. If your time allows you please have a look.(open MAIN)
    Thank You
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    There is no MAIN, there is jobs.

    What do you mean by 'not working'? The code works for me. Must hit 'Enter' or 'Tab' after typing the jobnumber to trigger the event.
    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.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  9. #9
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    Thank for trying the code. Did You open form "MAIN" and it worked by changing values in Combo11?
    Thanks.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    As already stated - there is no form MAIN, only jobs and therefore no Combo11.
    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.

  11. #11
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    My mistake. I loaded a different db (with a different code). This is the one with the code provided above.
    Thanks.
    Attached Files Attached Files

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Okay, combobox is on UNBOUND main form and records to be filtered are in subform.

    Code must be behind the combobox AfterUpdate, not the textbox because the textbox is a calculated value. AfterUpdate only triggers when data is input, not calculated.

    The value of combobox is ID but the code attempts to filter on JOBNUMBER field.

    This is a Navigation Form. I don't like and don't use them. I am having difficulty getting code that would work with a normal form to work with this.

    So another approach to consider is use of a single form set as Continuous then put combobox in that form's header (arrange controls to look like datasheet if you want). This I can get to work.

    Code:
    Private Sub Combo11_AfterUpdate()
    With Me.RecordsetClone
       .FindFirst "[ID]= " & Me.Combo11
    If Not .NoMatch Then Me.Bookmark = .Bookmark
    End With
    End Sub
    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.

  13. #13
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    This per your provided code.
    Attached Files Attached Files

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    So I should ignore the MAIN form code and only look at the ALLJOBS?

    Did you read my post thoroughly? Code in textbox AfterUpdate WILL NOT WORK.

    My suggested alternative is a solo form (just ALLJOBS) with a combobox in its Header.
    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.

  15. #15
    tazzzz is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    USA
    Posts
    37
    Database is huge and is setup as Navigation Form with more than 8 tabs. This is the only reason I try to make it work this way. I would change it for a solo form in a blink of an eye if others will agree with a different format.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. find values based on text criteria
    By boboivan in forum Access
    Replies: 2
    Last Post: 12-09-2015, 05:37 AM
  2. Replies: 3
    Last Post: 08-24-2015, 03:30 PM
  3. Replies: 2
    Last Post: 09-24-2014, 05:19 PM
  4. Replies: 7
    Last Post: 05-03-2014, 11:50 AM
  5. Replies: 2
    Last Post: 05-30-2012, 09:09 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