User InputBox to read SQL statement parameter : SQL Parameter « Access « VBA / Excel / Access / Word






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

1.Creat a SQL statement and append parameter as ceriteria
2.Creating a Parameter Query
3.Build the SQL statement dynamically
4.Running Parameter Queries
5.Executing a SQL Statement Containing Parameters