I have a pass through query but the stored procedure on SQL server requires a parameter.
How do I pass the parameter in the following code?
At the moment the pass through query just says:
EXEC Sproc @Name
Dim i As Integer
Dim iNumCols As Integer
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Query1")
Application.SetOption "Show Status Bar", True
StatusBar = SysCmd(acSysCmdSetStatus, "Formatting export file... please wait.")
'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.workBook
Dim oSheet As Excel.workSheet
'uncomment these 2 lines for debugging
'oApp.Visible = True
'oApp.UserControl = True
Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Add the field names in row 1
iNumCols = rs.Fields.Count
For i = 1 To iNumCols
oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
Next
'Add the data starting at cell A1
oSheet.Range("A2").CopyFromRecordset rs
How do I pass the parameter in the following code?
At the moment the pass through query just says:
EXEC Sproc @Name
Dim i As Integer
Dim iNumCols As Integer
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Query1")
Application.SetOption "Show Status Bar", True
StatusBar = SysCmd(acSysCmdSetStatus, "Formatting export file... please wait.")
'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.workBook
Dim oSheet As Excel.workSheet
'uncomment these 2 lines for debugging
'oApp.Visible = True
'oApp.UserControl = True
Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
'Add the field names in row 1
iNumCols = rs.Fields.Count
For i = 1 To iNumCols
oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
Next
'Add the data starting at cell A1
oSheet.Range("A2").CopyFromRecordset rs