shanedavid1981
Programmer
Hey,
I'm a bit stuck as to how I would pass a parameter from a form to a query in VBA... look at this:
Now when I run this Excel opens, but no data is delievered.. an error message in the background tells me a parameter is required... the query requires one parameter from the form this code is triggered from... what do I need to do to get this parameter passed correctly?
Thanks
)
I'm a bit stuck as to how I would pass a parameter from a form to a query in VBA... look at this:
Code:
Private Sub Command5_Click()
Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet
Dim xlWorkbook As Excel.Workbook
Dim acQuery As QueryDef
Dim objRST As Recordset
Dim strQueryName As String
Dim strquerytext As String
Combo2.SetFocus
strquerytext = Combo2.Text
strQueryName = "OpsAttSummarySearch"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
Set objRST = Application.CurrentDb.OpenRecordset(strQueryName)
Set xlSheet = xlWorkbook.Sheets(1)
With xlSheet
.Cells.CopyFromRecordset objRST
.Name = strquerytext
End With
Set objRST = Nothing
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub
Now when I run this Excel opens, but no data is delievered.. an error message in the background tells me a parameter is required... the query requires one parameter from the form this code is triggered from... what do I need to do to get this parameter passed correctly?
Thanks