Do.Cmd Open Form WHERE question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • birdbite
    New Member
    • May 2010
    • 2

    Do.Cmd Open Form WHERE question

    Hello, this is my first post. Thanks for reading.

    I am trying to open a form on a Click event where the records displayed are what the user has selected on several form combo boxes. Some of the combo boxes contain text and some numbers. I am getting a data mismatch erorr in Ac07 when I try to combine both data types in the same Where condition. Here is my code:

    Code:
    Dim strWhere As String
    
    strWhere = "[ID] = " & Me.cboID Or "[Type] = '" & Me.cboType & "'"
    
    DoCmd.OpenForm "MyForm", , , strWhere, acFormEdit
    Could it be because I am declaring this as a string? I tried a CInt(ID) but that didn't seem to work, but maybe my syntax was wrong.

    Thank you for your help!
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    The string wasnt being built correctly, try this instead:
    Code:
    strWhere = "[ID] = " & Me.cboID & " Or [Type] = '" & Me.cboType & "'"

    Comment

    • birdbite
      New Member
      • May 2010
      • 2

      #3
      That's the winner, thanks for your quick help!

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        Glad to help! Hope all your future questions go this quickly ;)

        Welcome to Bytes!

        Comment

        Working...