Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub NO6_Postcode()
- 'Connection Variables
- Dim cn As ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim cmd As ADODB.Command
- Set cn = New ADODB.Connection
- Set rs = New ADODB.Recordset
- Set cmd = New ADODB.Command
- ' Ranges
- Dim myRange As range
- Dim nextUsed As range
- Dim sqlQry As String
- Dim myCell As range
- Set myRange = range("A1:A10")
- Set nextUsed = range("F1:F10")
- 'connection to the database via DSN
- With cn
- .Provider = "MSDASQL"
- .ConnectionString = "DSN=localhostTest"
- .Open
- End With
- For Each myCell In myRange
- sqlQry = myCell.Text
- Set cmd.ActiveConnection = cn
- cmd.CommandText = "SELECT * FROM test WHERE name LIKE '" & sqlQry & "' "
- cmd.CommandType = adCmdText
- Set rs.Source = cmd
- rs.Open
- ActiveSheet.range("F1").CopyFromRecordset rs
- Next myCell
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement