Hi guys,
I have the following code
I'm just wondering if there is a faster way to do the same. Maybe without using a loop? Its currently taking 1min
I have the following code
VBA Code:
Sub test((
'This macro imports query into Excel
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim myValue As Variant
Dim strSQL As String
DBPass = InputBox("Enter Password")
Set dbs = OpenDatabase("U:\TEST1\test.accdb", False, False, ";pwd=" & DBPass & "")
'Get the parameter query
Set qdf = dbs.QueryDefs("Query_test1")
myValue = InputBox("Enter Code")
'Supply the parameter value
qdf.Parameters("Enter Code") = myValue
'Open a Recordset based on the parameter query
Set rst = qdf.OpenRecordset()
While Not rst.EOF
Sheets.Add.Name = "test"
With ActiveSheet.Range("A1") 'create field headers
lOffset = 0
For Each fld In rst.Fields
.Offset(0, lOffset).Value = fld.Name
lOffset = lOffset + 1
Next fld
End With
ActiveSheet.Range("A2").CopyFromRecordset rst, 150000
Wend
MsgBox "Access query export completed."
End Sub
I'm just wondering if there is a faster way to do the same. Maybe without using a loop? Its currently taking 1min