Error with Too few parameters

P

peddie

Hi

I am super newbie to writing VBA and I would like to ask for any of
your help please.

It is so simple but I dont where to start. i would like to set up a
text box which I could enter a string to search for name within the
database, and I would like the result to show in the Value list which
sits on the same form.

Then i want to be able to pick one value from the searh result in the
Value List and click the button to continue (by Continue I mean open a
new form that displays the selected record)

Any idea how to do this please?

This is the code



Private Sub Command4_Click()

'Declare the object variables
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL As String


List0.Visible = True
'Instantiate the objects and open the recordset
Set db = CurrentDb
strSQL = "SELECT * from Name where FullName = " & _
" Form!NameSearch!nmsearch"

Set rs = db.OpenRecordset(strSQL)

rs.Filter = Form!namesearch!nmsearch

List0.RowSource = nmsearch

'Clean up afterwards
On Error Resume Next
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing


End Sub

I seemed to get no where with this

Many thanks in advance
peddie
 
D

Douglas J Steele

The reference to the control on the form should not be in quotes, but the
value contained in that control needs to be.

Try:

strSQL = "SELECT * from Name where FullName = " & _
Chr$(34) & Form!NameSearch!nmsearch & Chr$(34)

Chr$(34) returns ": that's better than using a single quote ('), since
you'll run into problems with names like O'Connor if you use a single quote.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top