filter form form Unbound text box (1 Viewer)

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
Hi
i have a form and want to filter the form based on the number i enter in unbound text box to search the tow field ( Sealing Number 1 and Sealing Number 2 ) if found in any then filter the form.


i tried the code bellow but it does not work

Code:
If Me.Sealing_Number_1 = Me.TxtSealNo Then
Me.Filter = "[Sealing Number 1]  =" & Me.TxtSealNo
 Me.FilterOn = True
 ElseIf [Sealing Number 2] = Me.TxtSealNo Then
 Me.Filter = "[Sealing Number 2]  =" & Me.TxtSealNo
  Me.FilterOn = True
else 
MsgBox "No record"
 End If

any advise please
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:26
Joined
Jul 9, 2003
Messages
16,274
MsgBox No record"

Should be:-

MsgBox "No record"
 

Orthodox Dave

Home Developer
Local time
Today, 02:26
Joined
Apr 13, 2017
Messages
218
if Sealing_Number_1 and Sealing_Number_2 are text fields, then you need single quote-marks around them like this:-
Code:
If Me.Sealing_Number_1 = Me.TxtSealNo Then
Me.Filter = "[Sealing Number 1] = '" & Me.TxtSealNo & "'"
Me.FilterOn = True
ElseIf [Sealing Number 2] = Me.TxtSealNo Then
Me.Filter = "[Sealing Number 2] = '" & Me.TxtSealNo & "'"
Me.FilterOn = True
else 
MsgBox No record"
End If

I assume also you've taken account of the fact that you have underscores in some places "If Me.Sealing_Number_1" and not others "Me.Filter = "[Sealing Number 1] ="
 

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
if Sealing_Number_1 and Sealing_Number_2 are text fields, then you need single quote-marks around them like this:-
Code:
If Me.Sealing_Number_1 = Me.TxtSealNo Then
Me.Filter = "[Sealing Number 1] = '" & Me.TxtSealNo & "'"
Me.FilterOn = True
ElseIf [Sealing Number 2] = Me.TxtSealNo Then
Me.Filter = "[Sealing Number 2] = '" & Me.TxtSealNo & "'"
Me.FilterOn = True
else 
MsgBox No record"
End If

I assume also you've taken account of the fact that you have underscores in some places "If Me.Sealing_Number_1" and not others "Me.Filter = "[Sealing Number 1] ="


i tried but it just give me message " No record" but does not filter the form
 

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
even tried this way as bellow but got this message
" Compile error
method or data member not found

the code :
Me.Filter = "[Sealing Number 2] = " & Me.TxtSeal Or Me.Filter = "[Sealing Number 1] = " & Me.TxtSeal
Me.FilterOn = True
 

Minty

AWF VIP
Local time
Today, 02:26
Joined
Jul 26, 2013
Messages
10,368
Baby steps. as Dave said earlier is the sealing number stored as text or is it a number?

If its a number then get it working with one filter first.
Code:
 Me.Filter = "[Sealing Number 1] = " & Me.TxtSeal
It would probably really help if you removed the spaces from your field names before getting too far. They are a pain to type, easy to get wrong and add to the possible errors.
 

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
Baby steps. as Dave said earlier is the sealing number stored as text or is it a number?

If its a number then get it working with one filter first.
Code:
 Me.Filter = "[Sealing Number 1] = " & Me.TxtSeal
It would probably really help if you removed the spaces from your field names before getting too far. They are a pain to type, easy to get wrong and add to the possible errors.


as a number
 

Minty

AWF VIP
Local time
Today, 02:26
Joined
Jul 26, 2013
Messages
10,368
So does that code work on a single filter?
 

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
So does that code work on a single filter?


yes it work perfectly as below:
Me.Filter = "[Sealing Number 2] = " & Me.TxtSealNo
Me.FilterOn = True


but i want to search another field at the same time
 

Minty

AWF VIP
Local time
Today, 02:26
Joined
Jul 26, 2013
Messages
10,368
Okay then
Code:
Me.Filter = "[Sealing Number 2] = " & Me.TxtSealNo  & " OR [Sealing Number 1] = " & Me.TxtSealNo
Me.FilterOn = True
Should work
 

theinviter

Registered User.
Local time
Yesterday, 18:26
Joined
Aug 14, 2014
Messages
240
Okay then
Code:
Me.Filter = "[Sealing Number 2] = " & Me.TxtSealNo  & " OR [Sealing Number 1] = " & Me.TxtSealNo
Me.FilterOn = True
Should work


done successfully
thank you
 

Users who are viewing this thread

Top Bottom