Opening a filtered form on two different data type fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TADEL714
    New Member
    • Feb 2008
    • 2

    Opening a filtered form on two different data type fields

    I am trying to open a form based on the record set of the current form. The form I am opening should filtered based on a text field and a date field. The code I am using is as follows:
    Code:
    Private Sub Command100_Click()
    If Not Me.NewRecord Then
        DoCmd.OpenForm "FrmPulls", , , "[TEXT]='" & Me!TEXT & "'" And "[DATE]=#" & Me!DATE & "#", , acWindowNormal
    End If
    End Sub
    When I run the code I receive the error message "Run-time error '13': Type mismatch".

    When I hover over the arguments in debug mode the data is correct. What is causing this error message??

    Thanks
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by TADEL714
    ...When I run the code I receive the error message "Run-time error '13': Type mismatch".
    HI Tadel714. It's the quote marks in your filter string which are causing the problem - the AND is not within the string at present:
    Code:
    "[TEXT]='" & Me!TEXT & "'" And "[DATE]=#" & Me!DATE & "#", ,
    Change it to
    Code:
    "[TEXT]='" & Me!TEXT & "' And [DATE] = #" & Me!DATE & "#", ,
    -Stewart

    Comment

    • TADEL714
      New Member
      • Feb 2008
      • 2

      #3
      Originally posted by Stewart Ross Inverness
      HI Tadel714. It's the quote marks in your filter string which are causing the problem - the AND is not within the string at present:
      Code:
      "[TEXT]='" & Me!TEXT & "'" And "[DATE]=#" & Me!DATE & "#", ,
      Change it to
      Code:
      "[TEXT]='" & Me!TEXT & "' And [DATE] = #" & Me!DATE & "#", ,
      -Stewart
      That worked, thanks Stewart

      Comment

      Working...