Searching for names on a form

derlwyn

Registered User.
Local time
Today, 18:50
Joined
Mar 21, 2003
Messages
12
Hello,

I have a table of pupils names and a form to view the data.

What I want is a command button which would accept a surname to search for and then find the matches of that surname

I guess a start would be to find the firstmatch so I tried the following code

Private Sub cmdsearchbyname_Click()
Dim searchname As String


searchname = InputBox("Enter name to search for")
tblmembers.Recordset.FindFirst "[surname]=" & searchname
If tblmembers.Recordset.NoMatch Then
MsgBox ("No matches found for " & searchaname)
End If

End Sub


the table i am searching is called tblmembers and the field that I want to search is surname

When I run this I get the following error

run time error 424 object required

on this line

tblmembers.Recordset.FindFirst "[surname]=" & searchname

Any help would be greatly appreciated

I will deal with the problem of multiple matches later!

Thanks
 
Hello,

I have a table of pupils names and a form to view the data.

What I want is a command button which would accept a surname to search for and then find the matches of that surname

I guess a start would be to find the firstmatch so I tried the following code

Private Sub cmdsearchbyname_Click()
Dim searchname As String


searchname = InputBox("Enter name to search for")
tblmembers.Recordset.FindFirst "[surname]=" & searchname
If tblmembers.Recordset.NoMatch Then
MsgBox ("No matches found for " & searchaname)
End If

End Sub


the table i am searching is called tblmembers and the field that I want to search is surname

When I run this I get the following error

run time error 424 object required

on this line

tblmembers.Recordset.FindFirst "[surname]=" & searchname

Any help would be greatly appreciated

I will deal with the problem of multiple matches later!

Thanks

Here's a link to some examples
http://www.blueclaw-db.com/access_findfirst.htm
 
or you could use that funny search button near the top of the page button and find plenty of examples in the sample db section...
 
As others have pointed out, there are many other posts regarding this.
I'll give you a poke in the right direction though.

1) You want to set a variable to value of the text box
2) You want to create an SQL statement that finds the matching records
3) Pass the results into the form. A subform would work. (set the recordsource of the subform to the sql statement)
 

Users who are viewing this thread

Back
Top Bottom