Hi again,
Feel like I've asked a million questions recently, but here's another......
This code works perfectly fine to run an access query, and then paste the results in a sheet in my open excel document. No issue there.....
However, is there any way I can modify this to add a variable so that I can select only certain data? For example, adding in a "WHERE STATE_CODE = 'TX' " or something like that?
Private Sub CommandButton1_Click()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim DB
Dim vProvid
Application.ScreenUpdating = False
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
DB = "C:\Generic\Generic Access.mdb"
vProvid = "Microsoft.Jet.OLEDB.4.0" ' "SQLOLEDB"
With con
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "Data Source=" & DB
End With
Set rs = con.Execute("StateData")
ActiveWorkbook.Worksheets("Sheet1").Range("A1").CopyFromRecordset rs
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
Range("A5").Select
Application.ScreenUpdating = True
End Sub
Thanks!
Bookmarks