Searching For Text in a Field - Combobox vs Textbox (1 Viewer)

zashaikh

Registered User.
Local time
Yesterday, 16:05
Joined
Apr 28, 2017
Messages
13
I have a single form with 300 records. One the form I have a textbox called FISNumber where I record an identification number. I also have a textbox field called txtSearchFISNum and a button called btnSearchFISNum.

I want to be able to type in a number into txtSearchFISNum and press btnSearchFISNum, and then be taken to the exact record on my form where FISNumber = txtSearchFISNum.

This is what I am using:

Public Sub GoToSearchFISNumb(FISNumber As Long)
With Me.RecordsetClone
.FindFirst "[FISNumber] = '" & FISNumber & "'"
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
End Sub


Private Sub btnSearchFISNum_Click()
Me.GoToSearchFISNum Me.txtSearchFISNum
End Sub

However, the code doesnt work and only brings up the debug menu which highlights the second code.

I believe this is because the FISNumber field is my primary key and an autonumber and the txtSearchFISNum is a text field. I would prefer not to use a combo box because I will likely have several thousand FISNumbers in the future, and I do not want a dropdown of that many items.
 

isladogs

MVP / VIP
Local time
Today, 00:05
Joined
Jan 14, 2017
Messages
18,257
If it's a number, you need to change this line:
Code:
.FindFirst "[FISNumber] = '" & FISNumber & "'"

to

Code:
.FindFirst "[FISNumber] = " & FISNumber

BTW - you could just use code in the After_Update event of the textbox and scrap the button
 

zashaikh

Registered User.
Local time
Yesterday, 16:05
Joined
Apr 28, 2017
Messages
13
Thank you for the assistance. But I tried that method as well, but still no luck
 

missinglinq

AWF VIP
Local time
Yesterday, 19:05
Joined
Jun 20, 2003
Messages
6,423
It pretty much has to be a Number, since it's declared as a Long

Code:
[B]Public Sub GoToSearchFISNumb(FISNumber As Long)[/B]

If not, that may be the problem.

Since it's declared as a Public Sub, it would usually reside in a Standard Module, rather than in the Form's Module. Is that the case?

Linq ;0)>
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:05
Joined
May 7, 2009
Messages
19,246
On your second code you need to call the first code:


Private Sub btnSearchFISNum_Click()
Call GoToSearchFISNum (Me.txtSearchFISNum)
End sub
 

zashaikh

Registered User.
Local time
Yesterday, 16:05
Joined
Apr 28, 2017
Messages
13
Thank you for the help everyone. This is the new code:

Public Sub GoToSearchFISNumb(FISNumber As Long)
With Me.RecordsetClone
.FindFirst "[FISNumber] = " & FISNumber
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
End Sub


Private Sub btnSearchFISNum_Click()
Call GoToSearchFISNum(Me.txtSearchFISNum)
End Sub

I still recieve an error every time I press btnSearchFISNum. I am not being told "Compile Error: Sub or function not defined

And FISNumber is an autonumber and my primary key. txtSearchFISNum is a textbox where I enter the number I want to search (this is the FISNumber). btnSearchFISNum is the button that runs the code.
 

isladogs

MVP / VIP
Local time
Today, 00:05
Joined
Jan 14, 2017
Messages
18,257
Have you tried my suggestion from post #2?
you could just use code in the After_Update event of the textbox and scrap the button
 

Minty

AWF VIP
Local time
Today, 00:05
Joined
Jul 26, 2013
Messages
10,372
There is a typo;

Code:
Public Sub [COLOR="DarkOrange"]GoToSearchFISNumb[/COLOR](FISNumber As Long)
    With Me.RecordsetClone
        .FindFirst "[FISNumber] = " & FISNumber
        If Not .NoMatch Then Me.Bookmark = .Bookmark
    End With
End Sub


Private Sub btnSearchFISNum_Click()
    Call [COLOR="Red"]GoToSearchFISNum[/COLOR][COLOR="RoyalBlue"]b[/COLOR](Me.txtSearchFISNum)
End Sub

Missing the B at the end of the call
 

zashaikh

Registered User.
Local time
Yesterday, 16:05
Joined
Apr 28, 2017
Messages
13
Ridders, I would prefer a button.

And Minty, THANK YOU! That typo fixed it!
 

isladogs

MVP / VIP
Local time
Today, 00:05
Joined
Jan 14, 2017
Messages
18,257
Fair enough.
Glad you (Minty really) got it working
 

Users who are viewing this thread

Top Bottom