Open and Filter form based on Combo Box Selection

S

slack.steve

I have a unbound form with a combo box that when selected and a button
pressed it opens up a form filtered based on the combo box selection.
I have made O1Var a global variable.

This is the code for the button on the unbound form:
Private Sub Command568_Click()
On Error GoTo Err_Command568_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Results_Form"

If Forms!Query_form2!Osteoarthritis = "X" Then
O1var = "X"
Else
O1var = "*"
End If

DoCmd.OpenForm stDocName, , , , , , stLinkCriteria


Exit_Command568_Click:
Exit Sub

Err_Command568_Click:
MsgBox Err.Description
Resume Exit_Command568_Click

End Sub

Then on the On Open Property, I have this code -

Private Sub Form_Open(Cancel As Integer)

MsgBox "O1Var =" & O1var

DoCmd.ApplyFilter , Osteoarthritis = O1var

End Sub

When I try to run it prompts me for the value of O1var.
Any help would be appreciated!
 

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

Top