In Access 2007, I am searching a table to find a certain ID. The ID address is given in a text box by the user IDTxt.
I get error 80040e10 no value for one or more parameters.
Private Sub Search_Click()
'here a new part I'm not sure about...
Dim cn As ADODB.Connection
Dim rsQ As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rsQ = New ADODB.Recordset
Dim strSQL As String
Dim ID_number As Integer
Dim blnExists As Boolean
blnExists = False
ID_number = IDTxt.Value
strSQL = "SELECT * FROM Table1 WHERE ID = ID_number;"
rsQ.Open strSQL, cn, adOpenStatic
If rsQ.RecordCount <> 0 Then
' Found it
blnExists = True
MsgBox "found"
Else
MsgBox "not found"
End If
End Sub
Your passing a string without substituting the value;
needs to be
as
ID_numberis only in the context of a VBA variable outside the string.(Your also not performing type checking on
ID_numberso text in an unrestricted textbox could error, and for string parameters is an injection vulnerability)Also note that
RecordCountcan return-1depending on cursor location/type.