Search Enter

Valentine

Member
Local time
Today, 14:15
Joined
Oct 1, 2021
Messages
261
I created a button that searches for what i put in a text box. The search works perfectly if i click the button after entering my text. What I was wondering is, how do i make it work by hitting "enter" after typing my text?
 
Try setting the Default property for the button to Yes.
 
OMG!!!!! thank you soo much it has caused me headaches that every time i hit enter after putting in my text and just go oh right gotta hit the button
 
OMG!!!!! thank you soo much it has caused me headaches that every time i hit enter after putting in my text and just go oh right gotta hit the button
You're welcome. Good luck with your project.
 
New question, same topic. I needed to go with multiple search options in the database: Name, ID, SID. I made a search for each line but since its 3 different buttons I cannot hit enter to search. Is there a way to keep all 3 and just have the enter work if the field has data?
 
New question, same topic. I needed to go with multiple search options in the database: Name, ID, SID. I made a search for each line but since its 3 different buttons I cannot hit enter to search. Is there a way to keep all 3 and just have the enter work if the field has data?
Hmm, why do you have/need three different buttons for searching? Can you post a screenshot of your search form?
 
Search.PNG

Some soldiers do not have SIDs but 95% do so its a valid search, DoD ID everyone has but hard to remember at the time to search, name is fastest way to search of course searches by last name. I could put them all into 1 button but was seeing if there was a way to keep the 3.
 
View attachment 100187
Some soldiers do not have SIDs but 95% do so its a valid search, DoD ID everyone has but hard to remember at the time to search, name is fastest way to search of course searches by last name. I could put them all into 1 button but was seeing if there was a way to keep the 3.
I would suggest maybe using three textboxes and one button. Or better yet, one textbox, an option group to select the search type, and one button.
 
Ok so what i feared is what would have to happen. Have to make 1 button and put all three types of search together. Thank you
 
Ok so what i feared is what would have to happen. Have to make 1 button and put all three types of search together. Thank you
Not necessarily "together." Instead, think of it as three separate branches. One button to decide which route to take (or, which search to make).
 
yeah I know not "together" but 1 text box instead of 3 is all I meant, I kinda like the simplicity that it is now so I will just tell the few that want the "enter" option they are SOL.
 
Why?
You choose the category,enter the search criteria and press Enter
 
yeah I know not "together" but 1 text box instead of 3 is all I meant, I kinda like the simplicity that it is now so I will just tell the few that want the "enter" option they are SOL.
Well, don't give up just yet. Assuming the user will fill in the desired Textbox to search before hitting Enter, then you could remove the Default setting and simply use the AfterUpdate event of each Textbox to perform the search (by calling the corresponding button code).
 
Ok I changed it to 1 button but I am getting type mismatch errors after the search has happened. I enter the appropriate info and the search finds what I'm looking for and then I get a type mismatch error.

Code:
    If Me.cboChoice.Value = "SID" Then
        SIDSearch ("' & txtChoice & '")
    ElseIf Me.cboChoice.Value = "DoD ID" Then
        DoDSearch (" & txtChoice & ")
    ElseIf Me.cboChoice.Value = "Name" Then
        NameSearch ("' & txtChoice & '")
    End If
Thats my button code

Code:
    Dim dbCurr As DAO.Database
    Dim rstDod As DAO.Recordset
    Dim strDoD As String
    
    Set dbCurr = CurrentDb()
    Set rstDod = Me.Recordset
    strDoD = Me.txtChoice.Value
    rstDod.FindFirst "[DoD ID] = " & strDoD
        If rstDod.NoMatch Then
            MsgBox "Record not found for DoD ID# " & strDoD
        End If
    Me.txtChoice.Value = ""
    Set rstDod = Nothing
    Set dbCurr = Nothing

That's what all the search functions look like with subtle changes for DoD ID, SID, and Name.
 
Ok I changed it to 1 button but I am getting type mismatch errors after the search has happened. I enter the appropriate info and the search finds what I'm looking for and then I get a type mismatch error.

Code:
    If Me.cboChoice.Value = "SID" Then
        SIDSearch ("' & txtChoice & '")
    ElseIf Me.cboChoice.Value = "DoD ID" Then
        DoDSearch (" & txtChoice & ")
    ElseIf Me.cboChoice.Value = "Name" Then
        NameSearch ("' & txtChoice & '")
    End If
Thats my button code

Code:
    Dim dbCurr As DAO.Database
    Dim rstDod As DAO.Recordset
    Dim strDoD As String
    
    Set dbCurr = CurrentDb()
    Set rstDod = Me.Recordset
    strDoD = Me.txtChoice.Value
    rstDod.FindFirst "[DoD ID] = " & strDoD
        If rstDod.NoMatch Then
            MsgBox "Record not found for DoD ID# " & strDoD
        End If
    Me.txtChoice.Value = ""
    Set rstDod = Nothing
    Set dbCurr = Nothing

That's what all the search functions look like with subtle changes for DoD ID, SID, and Name.
Which line is highlighted when you go to debug mode?
 
the lines that call upon the functions. Depending on what i search for is what line is highlighted so apparently I have a problem with all 3 functions or just how I am passing my variables into the function.
 
ok i figured it out. I needed to add ByRef txtChoice into the functions () so they would read Private Function NameSearch(ByRef txtChoice) sorry for the silly mistake.
 
And there is me thinking it was the default? :(
 
I am facing a problem in search box. Guide me best tips and trick for finding large amount of data from old records.
 
I am facing a problem in search box. Guide me best tips and trick for finding large amount of data from old records.
Hi. Welcome to AWF!

May I suggest you start a new thread to discuss your request?
 

Users who are viewing this thread

Back
Top Bottom