C
Corinne
I have a single table with dozens of fields. I used the input mask for
things such as SSN (social security number-also my Primary Key), phone
numbers, and birthdates. Through this Discussion Group I found a reference
to site that gave me code to put a search for record box at the top of a form
I created. The first time I put in my SSN that I knew matched one in my
table it told me it couldn't find a matching record, but it displayed that
"person's" record on the screen below my search field like it was supposed
too. Unfortunately, since that first record, when I put in an SSN that I
*KNOW* is in my table, it says it can't find a value. Then randomly, I'll
enter a different SSN and it will find it, not listing any errors. Since my
search is based around SSN I used the input mask on the search box thinking
maybe my search wasn't able to find the records because of mask, but that
didn't work either.
Below is the code I'm using for my Search button's event proceedure:
Option Compare Database
'--------------------------------------------------------------
'Graham Thorpe 25-01-02
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("SSN")
DoCmd.findrecord Me!txtsearch
SSN.SetFocus
strStudentRef = SSN.Text
txtsearch.SetFocus
strSearch = txtsearch.Text
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
SSN.SetFocus
txtsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtsearch.SetFocus
End If
End Sub
Any help you can offer as to why this search isn't consistently returning
records that ARE in the table, I would really appreciate. I have spent well
over 50 hours trying to create a search button, and to be so close is
extremly frustrating.
Thank you
things such as SSN (social security number-also my Primary Key), phone
numbers, and birthdates. Through this Discussion Group I found a reference
to site that gave me code to put a search for record box at the top of a form
I created. The first time I put in my SSN that I knew matched one in my
table it told me it couldn't find a matching record, but it displayed that
"person's" record on the screen below my search field like it was supposed
too. Unfortunately, since that first record, when I put in an SSN that I
*KNOW* is in my table, it says it can't find a value. Then randomly, I'll
enter a different SSN and it will find it, not listing any errors. Since my
search is based around SSN I used the input mask on the search box thinking
maybe my search wasn't able to find the records because of mask, but that
didn't work either.
Below is the code I'm using for my Search button's event proceedure:
Option Compare Database
'--------------------------------------------------------------
'Graham Thorpe 25-01-02
'--------------------------------------------------------------
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("SSN")
DoCmd.findrecord Me!txtsearch
SSN.SetFocus
strStudentRef = SSN.Text
txtsearch.SetFocus
strSearch = txtsearch.Text
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
SSN.SetFocus
txtsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try
Again.", _
, "Invalid Search Criterion!"
txtsearch.SetFocus
End If
End Sub
Any help you can offer as to why this search isn't consistently returning
records that ARE in the table, I would really appreciate. I have spent well
over 50 hours trying to create a search button, and to be so close is
extremly frustrating.
Thank you