[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

How do you use a combox on single form, that will open and filter another form?

I used the attach code to do virtually the identical thing with a report.  Using a combobox to filter the results of a report, and I'm having no luck transferring the same concept to opening a form rather than a report.  The user would choose to enter data on a form, and seperate form with a single combobox would pop up anking for details, which would then filter out the main form.

Code I've been trying to use is below
Private Sub cboChooseOption_AfterUpdate()
    MsgBox Me!cboChooseOption.Column(0)
    MsgBox VarType(Me!cboChooseOption.Column(0))
    On Error GoTo Err_cmdFormApp_click:
    Dim FormName
    FormName = "frmAddDataForOptionChosen"
    DoCmd.OpenForm _
        FormName:=FormName, _
        Wherecondition:="[PK] = '" & Me!cboChooseOption.Column(0) & "'"
    Exit Sub
    If Err.Number = 2501 Then
    Else: MsgBox Err.Description
    End If
    GoTo Exit_cmdFormApp_Click
End Sub

Open in new window

  • 2
1 Solution
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Try this:
Ii PK is Numeric

Wherecondition:="[PK] = "  & Me.cboChooseOption.Column(0)

If PK is a String:

Wherecondition:="[PK] = "  & Chr(34) &  Me.cboChooseOption.Column(0) & Chr(34)

Matt330Author Commented:
That was it - it was because PK was numeric.  Thanks again MX!  I'll figure out what all these single quote/ triple-double quotes  mean eventually.
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
you are welcome.  Chr(34) is a double quote ... used for clarity in posting.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now