-
VBA Error Please Help
Here's my code for running a query and outputting it to an Excel spreadsheet. I receive this error:
"No value given for one or more required parameters"
The place where I receive the error is in red below. I've made sure the spelling is correct on the query name. "DTC_Output" The weird thing is this worked yesterday and I tried it today and I'm getting this error and I don't believe I changed anything. Any ideas?
Public Function Output_DTC()
Dim cnn As ADODB.Connection
Dim MyRecordSet As New ADODB.Recordset
Dim MySQL As String
Dim MyExcelPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Set cnn = CurrentProject.Connection
MyRecordSet.ActiveConnection = cnn
MySQL = "SELECT * FROM "
MySQL = MySQL & "DTC_Output"
MyRecordSet.Open MySQL
MyExcelPath = "\\Mer2-corpfs1\dnsc\Resource Management\Hasselgren\Auto Reports\TravelDoc Report\TravelDoc Template.xls"
Set Xl = CreateObject("excel.application")
Set XlBook = GetObject(MyExcelPath)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets("DTC")
XlSheet.Range("A2").CopyFromRecordset MyRecordSet
MyRecordSet.Close
Set cnn = Nothing
Set Xl = Nothing
XlBook.Save
XlBook.Close
Set XlBook = Nothing
Set XlSheet = Nothing
End Function
-
what happens when you open the query directly? does it also prompt you for parameters
steve
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules