I have reviewed some old posts about parameter queries, and they have been helpful but have not directly addressed my
question. I am trying to run an append query from VBA. The idea is to select a nember of values from a combobox
control and pass them as parameters to an append query that will append the appropriate records to a table.
At present I am doing this by running a “DoCmd.RunSQL” command and manipulating the SQL string – I think
the paramquery should be faster (but I won’t know until I get it working ).
Extracting the values from the combobox is working in the SQL/text manipulation version.
The code in the class module looks like this:
Private Sub Command33_Click() Dim dbs As Database Dim rst As Recordset Dim qdf As DAO.QueryDef Dim Sel As Integer Dim ctlList As Control Dim ctlActive As Control Dim Item As Variant Dim stDocName As String Set dbs = CurrentDb Set qdf = dbs.querydefs("qryPropEvalandStatus2MkTable") this is the parameter query - it is looking for an integer parameter "Selected" Set ctlList = Forms!frmPrintReports!lstbxRFPSelectList For Each Item In ctlList.ItemsSelected Sel = ctlList.ItemData(Item) qdf("[Selected]") = Sel I am trying to pass the 'Sel' value taken from the listbox to the query. It "seems" to be working - when the code chokes in the next line "Sel" and qdf("[Selected]") both have a value representative of the first value selected in the listbox. I could cut out the "Sel" variable, but that snippet is just taken out of the text manipulating version that works - minor touchups to come later! Set rst = qdf.OpenRecordset(dbOpenDynaset) At this point I get an illegal operation warning - THUMPNext Item rst.Close dbs.Close Set dbs = Nothing Set rst = Nothing Set qdf = Nothing End Sub
So – is it even possible to run an action query using the OpenRecordset
method – and if so, with what settings?
If not, is it possible to run an action query from within VBA, other than by the
CoCmd.RunSQL approach – and if so, how?