MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Sub RunAccessQueries() Dim cnn As ADODB.Connection Dim strQuery As String Dim cmd As ADODB.Command Dim rst As ADODB.Recordset Dim prm As ADODB.Parameter, prms As ADODB.Parameters Dim wks As Worksheet Dim i As Long Dim varSheetName As String varSheetName = "QUERY1" Set cnn = New ADODB.Connection With cnn .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = "Data Source=C:\db.mdb;" .Open End With Set wks = Sheets.Add wks.Name = varSheetName strQuery = "[" & varSheetName & "]" Set cmd = New ADODB.Command With cmd Set .ActiveConnection = cnn .CommandText = strQuery .CommandType = adCmdTable .Parameters.Refresh .Parameters("[Report date]").Value = dteReportDate1 .Parameters("[Report date 2]").Value = dteReportDate2 End With Set rst = New ADODB.Recordset rst.Open cmd With rst If Not (.EOF And .BOF) Then For i = 1 To .Fields.Count wks.Cells(1, i) = .Fields(i - 1).Name Next i wks.Range("A1").CopyFromRecordset rst End If End With rst.Close cnn.Close Set rst = Nothing Set cmd = Nothing Set cnn = Nothing End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|ActiveX component can't create object VBA how to fix it||6||60|
|how to read data from all excel sheet and copy it in in Master sheet||2||24|
|need count any combinaton of 4 numbers||7||23|
Join the community of 500,000 technology professionals and ask your questions.