Form with search textbox & button

sailorguy

Registered User.
Local time
Today, 04:19
Joined
Jan 31, 2008
Messages
48
Hi,

I have a simple form with one record displayed with just a couple fields. I have an unbound textbox and command button to use as a search field to find a certain record. The problem is that I'm searching on the "TN" field which is stored in the table with a mask "000 0 00 00" which causes a problem with the search because it ends up taking the string from the unbound textbox without the mask "000000000". So there's no result returned.

I'm not sure this makes any sense....

Here's the code for the search

Private Sub Command18_Click()

Dim SearchTN As String
Dim TNs As String

If IsNull(Me![SearchTN]) Or (Me![SearchTN]) = "" Then
MsgBox "Please Enter A TN to Search!", vbOKOnly, "Invalid Search!"
Me![SearchTN].SetFocus
Exit Sub
End If

DoCmd.ShowAllRecords
DoCmd.GoToControl ("TNs")
DoCmd.FindRecord Me!SearchTN

If Me!SearchTN = Me!TNs Then
MsgBox "TN Found:" & Me!SearchTN
Else
MsgBox "Match Not Found For: " & Me!SearchTN & " - Please Try Again."
Me.SearchTN.SetFocus
End If


End Sub
 
The problem is that I'm searching on the "TN" field which is stored in the table with a mask "000 0 00 00" which causes a problem with the search because it ends up taking the string from the unbound textbox without the mask "000000000". So there's no result returned.
Well, how about putting a mask into the textbox to fix it? You should be able to put one in there. How about this:
Code:
000\ 0\ 00\ 00
 
Hey I dont know how to tell you to write this code but I downloaded this and cut and pasted it into one of my forms and renamed some of the code fields and it works perfectly. Maybe you can use it to.

It's compliments of Develop.co.uk
 

Attachments

Thanks, I confirmed my code appears to be pretty much o.k. now....BUT I think the problem is that the search is taking the input from the textbox without keeping the input mask when it searches the table. The data is stored in the table with an input mask of 000\ 0\ 00\ 00;; This same mask is being used on the textbox for the search.

For testing I tried to remove the mask on the table and change one record using no spaces...then tried the same code and it worked.

Now what?:confused:
 
Thanks, I confirmed my code appears to be pretty much o.k. now....BUT I think the problem is that the search is taking the input from the textbox without keeping the input mask when it searches the table. The data is stored in the table with an input mask of 000\ 0\ 00\ 00;; This same mask is being used on the textbox for the search.

For testing I tried to remove the mask on the table and change one record using no spaces...then tried the same code and it worked.

Now what?:confused:

O.k. found the problem after searching the forum a little longer. I had to change the mask to 000\ 0\ 00\ 00;0; in the table and the unbound text box!
 

Users who are viewing this thread

Back
Top Bottom