I am trying to query a table in Access from a form where in the first text box I enter a name in the form of Lastname,Firstname MI. I then click a button to do the search(query). the bulk of the procedure code is below and its suppose to return values for the other two fields into the other two text boxes I have on the form.
Option Explicit
Dim Oconn As New ADODB.Connection
Dim rst As New ADODB.Recordset
(Above in general declarations)
Private Sub cmdSearch_Click()
Dim strSQL As String
Oconn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:db11.mdb;" & _
"Uid=admin;" & _
"Pwd="
If Text1.Text <> "" Then
strSQL = "SELECT * FROM MRListing WHERE (((MRListing.Name) = " & Chr(34) & Text1.Text & Chr(34) & "));"
End If
Set rst = Oconn.Execute(strSQL)
With rst
If .EOF And .BOF Then
MsgBox "No records found"
Else
.MoveFirst
Text2.Text = .Fields(1)
Text3.Text = .Fields(2)
End If
End With
End Sub
I am now getting the error :
[Microsoft][OBDC Microsoft Access Driver]Too Few Parameters. Expected 1
The error occurs when the string is executed.
I also need to probably set up the query to pull on the value of the second box as well. IT will just pulls the value for the third box from the database since people might have a common name but different birthdates. Any suggestions would be welcomed. Thanks.
13-08-2002 at 02:09 PM
|
Coyote Level: Guest
Re: Help with Access related form Archived to Disk
Hi Yea,
Just looking see two changes that may help.
First On here it looks like you left a slash out of your DB path. BUT - then when I previewed my response it killed my slash in th path. Funky... anyway - check that.
Next as for the error you posted - Need to revise your SQL statement as follows and this should work:
strSQL = "SELECT * FROM MRListing WHERE MRListing.Name = " & Chr(39) & Text1.Text & Chr(39) & ";"