Results 1 to 4 of 4
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Filter on Autonumber

    I have a field that is an Autonumber (Metric Number). I am attempting to filter the form based upon that field in the table. Below is my code. However, I get a "Type mismatch" error on the [Metric Number] filter (very last filter in IF statements). Any ideas? Is my syntax wrong for the filter since it is a number field?

    Code:
        Dim varMetricName, varDataNumber, varMetricNumber
        
        varDataNumber = Form_frmFindMetric.cboDatamartName.Value
        varMetricName = Form_frmFindMetric.cboMetricName.Value
        varMetricNumber = Form_frmFindMetric.cboMetricNumber.Value
        If varDataNumber <> "" Then
            'Do Nothing
        'Else
            If varMetricNumber = "" Then
                If varMetricName = "" Then
                    Me.Filter = "[Datamart Name] = """ & varDataNumber & """"
                    Me.FilterOn = True
                Else
                    Me.Filter = "[Metric Name] = """ & varMetricName & """"
                    Me.FilterOn = True
                End If
            Else
                Me.Filter = "[Metric Number] = """ & varMetricNumber & """"
                Me.FilterOn = True
            End If
        End If


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For a numeric value:

    Me.Filter = "[Metric Number] = " & varMetricNumber
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That's it...Wish the syntax could be the same on Dlookups, Filters, etc. Thanks pbaldy!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. The syntax for a DLookup would look about the same, for a numeric data type.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. duplicate autonumber
    By rayc in forum Access
    Replies: 5
    Last Post: 06-19-2013, 07:50 AM
  2. Autonumber gone crazy
    By asearle in forum Access
    Replies: 1
    Last Post: 07-27-2010, 05:41 AM
  3. Add prefix to AutoNumber
    By sirmilt in forum Database Design
    Replies: 3
    Last Post: 07-09-2010, 01:41 PM
  4. Controlling autonumber
    By Patience in forum Access
    Replies: 3
    Last Post: 06-22-2010, 04:11 AM
  5. AUTONUMBER
    By J A F F A in forum Database Design
    Replies: 1
    Last Post: 10-03-2007, 10:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums