PDA

View Full Version : Use Form to Search Records



CreganTur
03-27-2008, 09:43 AM
I've got a form that will be used to search records by an account number, and then display matching fields ([CDate], [RCD], and [FNotes]).

I've got it setup so that the search works- when an account number is entered into the field (and user hits enter) the correct record appears. I'm using this code:

Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[AcctNmbr] = '" & Me![Text4] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

First problem:

I want a MsgBox to appear if the user enters an invalid account number. I tried using this directly after the "If Not" statement in the above code, but I get an error message stating that there's an "Else without an If"

Else
MsgBox "There are no results for the specified account number." & vbCrLf & _
"Please enter a different account number.", vbExclamation + vbOKOnly, "No Results"
End If

Second problem:

I want the form, On Open, to be blank. Currently, On Open, the [CDate],[RCD], and [FNotes] fields are all showing data that matches the first record of the query that's providing the data.

Any ideas? :help

Carl A
03-27-2008, 10:18 AM
I've got a form that will be used to search records by an account number, and then display matching fields ([CDate], [RCD], and [FNotes]).

Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[AcctNmbr] = '" & Me![Text4] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark


Try:

If Not rs.NoMatch then

I get an error message stating that there's an "Else without an If"
This is sometimes caused by a (With - End With) where the End With is Missing

Trevor
03-27-2008, 11:40 AM
for the error message of an invaid # entered , loop through the RSt strcomp([Tex14], staccount#, vbbinarycompare) <> 0 Then msgbox
note this isn't full code just a guide , the strcomp vbbinarycompare is an exact mach test between text14.value, and the value in the table it is looking at
or you can simply drop the strcomp, vbbinarycompare and use text14 = staccount#
text14 = value in textbox
staccount3 = value assinged to that field in backend as varable