|
こんにちは
ちょっと書き方違っちゃいますけど・・・
Sub ADO_Find()
Dim cn As ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim mySQL As String
Dim strcriteria As String
Dim strback As String
Dim strSNTXT As String
Dim strSN As String
strSNTXT = "txtSNInput"
strSN = Worksheets("Sheet1").txtSNInput.Text
strback = Trim(strSN)
mySQL = "SELECT * FROM tbl1 WHERE fldA=" & strSNTXT
Set cn = New ADODB.Connection
cn.Open "provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=K:\db1.mdb"
With cmd
.ActiveConnection = cn
.CommandText = mySQL
.CommandType = adCmdText
.Prepared = True
.Parameters(0).Value = strback
End With
Set rs = New ADODB.Recordset
Set rs = cmd.Execute '← ここでエラーがでます。
Do Until rs.EOF
Debug.Print rs!fldA, rs!fldB, rs!fldC
rs.MoveNext
Loop
Set cmd = Nothing
rs.Close: Set rs = Nothing
cn.Close: Set cn = Nothing
End Sub
|
|