User InputBox to read SQL statement parameter
Sub command_parameters()
Dim conn As New Connection
Dim rec As New Recordset
Dim comm As New Command
Dim ws As Worksheet
Dim i&, countryname$
Set ws = ThisWorkbook.Worksheets("command")
conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
"Data Source=" + ThisWorkbook.Path + "\nwind.mdb;"
Set comm.ActiveConnection = conn
comm.CommandText = "SELECT companyname FROM customers WHERE country = ?"
countryname = InputBox("Please type in a country name (i.e. 'germany').")
comm.Parameters(0) = countryname
rec.Open comm
ws.[a1].CopyFromRecordset rec
rec.Close: conn.Close
End Sub
Related examples in the same category