Help with VBA (open query)



I have one command button used to open a form. How can I change if I
wan to open a query instead of form? I try with this but it doesn't
works. Something wrong with the code?
Or I use the wrong method?
strQuery = "grouping" (query name)
DoCmd.openquery strQuery, , , strSQL

Private Sub openform_Click()
Dim strSQL As String
Dim strWhere As String

If Not IsNull(tool_id) Then
strWhere = strWhere & " AND tool_id= " & "'" & tool_id & "'"
End If

If Not IsNull(cboStatus) Then
strWhere = strWhere & " AND status= " & "'" & cboStatus & "'"
End If

If Not IsNull(strWhere) Then
strSQL = Mid$(strWhere, 6)
End If

strForm = "history"
DoCmd.openform strForm, , , strSQL



OpenQuery doesn't have the same parameters as OpenForm
(Have a look in the help)

The following would open your query...

strQuery = "grouping" (query name)
DoCmd.openquery strQuery

If you need the query to be filtered by tool_id etc then you need to use
parameters in the query itself.


Andy Hull

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question