R
Rohn
txtSearch is the text box on the same form as the button with this VB
control.
control.
Klatuu said:Is txtSearch the name of a control on the form the code is in or it is on
a
subform or different form?
--
Dave Hargis, Microsoft Access MVP
Rohn said:Thanks for the explaination of the two fields. I took out the first
field
since we are searching for Alphanumeric data (like Z004 or Y142K).
The new error is a Compile Error: Invalid or Unqualified Reference on:
..txtSearch in this peice of the code.
'Use this if the table field Unit_ID is text
.FindFirst "[Unit_ID] = """ & Me.txtSearch & """"
Thanks for sticking with this issue!
Klatuu said:You are using both versions of what should be one line.
'Use this if the table field Unit_ID is numberic
.FindFirst "[Unit_ID] = " & Me.txtSearch
'Use this if the table field Unit_ID is text
.FindFirst "[Unit_ID] = """ & Me.txtSearch & """"
As the comments say, if Unit_ID ia a numeric field in the form's record
set,
use the first version and delete the second version. If it is a text
field,
delete the first version and use the second version. Note the text
version
encloses the search value in quotes which is correct syntax when
seaching
for
text. You do not use any delimiters when seaching for a numeric value.
And,
FYI, if you are searching a date field, the delimiters are the # sign:
.FindFirst "[Unit_ID] = #" & Me.txtSearch & "#"
--
Dave Hargis, Microsoft Access MVP
:
great, I added the revised wording. No errors but the search button
is
not
finding existing values! Here is the revised code.
'Performs the search using value entered into txtSearch
'and evaluates this against values in UNIT_ID field
Private Sub cmdSearch_Click()
'Check txtSearch for Null value or Nill Entry first.
If Nz(Me.txtSearch, vbNullString) = vbNullString Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search
Criterion!"
Me.txtSearch.SetFocus
Else
With Me.RecordsetClone
'Use this if the table field Unit_ID is numberic
.FindFirst "[Unit_ID] = " & Me.txtSearch
'Use this if the table field Unit_ID is text
.FindFirst "[Unit_ID] = """ & Me.txtSearch & """"
If .NoMatch Then
MsgBox "Match Not Found For: " & strSearch & " - Please
Try
Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
Else
MsgBox "Match Found For: " & strSearch, ,
"Congratulations!"
Me.Unit_ID.SetFocus
Me.txtSearch = vbNullString
End If
End With
End If
End Sub
Another whoopsy, sorry, but it is hard to get it right without VBE
correcting
me as I go. This line:
.FindFirst "[Unit_ID] = " & .txtSearch
Should be
.FindFirst "[Unit_ID] = " & Me.txtSearch