mercredi 6 juillet 2016
Pass VBA Variable into Access Query(Excel VBA)
Im new at trying to construct queries out of vba. I am trying to figure out how to pass a variable inside the VBA syntax. Mind showing me where im dumb?
I tried this below but there's an automation error that pops up. Ive noticed from playing aroudn that automation errors come up when youve just got syntax wrong, so hopefully its something small?
Any help is greatly appreciated
Sub GetDataFromAccess()
Dim cmd As New ADODB.Command, rs As ADODB.Recordset
Dim recordNum As Integer
recordNum = 7
cmd.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersAshleysaurusDesktop" & "" & "xyzmanu3.accdb"
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT * FROM Invoice WHERE OrderNumber <" & "'" & recordNum & "'" & "ORDER BY OrderNumber ASC"
Set rs = cmd.Execute
Sheet1.Range("A2").CopyFromRecordset rs
rs.Close
cmd.ActiveConnection.Close
Debug.Print "Done!"
End Sub
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire