Search Enter (1 Viewer)

Valentine

Member
Local time
Yesterday, 20:55
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?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
Try setting the Default property for the button to Yes.
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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.
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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?
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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.
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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).
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:55
Joined
Sep 21, 2011
Messages
14,231
Why?
You choose the category,enter the search criteria and press Enter
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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).
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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?
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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.
 

Valentine

Member
Local time
Yesterday, 20:55
Joined
Oct 1, 2021
Messages
261
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:55
Joined
Sep 21, 2011
Messages
14,231
And there is me thinking it was the default? :(
 

johnybell1

New member
Local time
Today, 05:55
Joined
Apr 28, 2022
Messages
1
I am facing a problem in search box. Guide me best tips and trick for finding large amount of data from old records.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:55
Joined
Oct 29, 2018
Messages
21,453
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

Top Bottom