Hi,
I'm working in Access '97 and I'm trying to update a subform with the new results of a query.
I use a combo box for a user to pick a state, then I have a command button that executes the query using the following code:
I don't know how to update the subform. It runs the query, but the results are posted in a datasheet view just like if you were to run a query with the design wizard.Code:Dim dbs As Database, rst As Recordset Dim qdf As QueryDef Dim strVariable As String Dim strSql As String On Error GoTo errUpdate_Click 'Deletes the previous query DoCmd.DeleteObject acQuery, "FindState" 'Gets the State variable strVariable = Forms!frmStateSelectNew.cmbStateSelect 'Now begins the action Set dbs = CurrentDb strSql = "SELECT DISTINCT * FROM OTC_SITES WHERE SITE_STATE = " & "'" & strVariable & "'" Set qdf = dbs.CreateQueryDef("FindState", strSql) 'Run Query DoCmd.OpenQuery qdf.Name Set qdf = Nothing Set dbs = Nothing 'DoCmd.OpenForm "FindState" Exit Sub errUpdate_Click: If Err = 3011 Then Resume Next Else MsgBox Err & Error$, vbCritical, "Error Occurred" End If Exit Sub
What I would like it to do is run the query without showing the records, then updated the subform with the new results.
How can I do this?
Thanks,
JazzBass




Reply With Quote