Results 1 to 11 of 11
  1. #1
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501

    filter by starts with number

    I am sure this is easy but I am spacing on how I would use a filter by form to find any records where the field value starts with a specific number. If it were text I would use like "72*" but it is a number so I am not sure how to do it. The values in the field can range between 4 and 6 characters.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Use Left() and Cstr() ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    add another field to the query where you convert the field to string: cStr([numField])
    then use your filter : like "72*" in THAT field.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    It depends on the datatype of the field. A text field can contain a number and needs delimiters, but a number field cant contain text.
    Is it all numbers or text also?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Welshgasman View Post
    Use Left() and Cstr() ?
    Do not even need the cstr(), but test anyway.
    Code:
    ? forms!frmDailyEntry!sfcsfrmDaily.form.dailyid
     3084 
    ? left(forms!frmDailyEntry!sfcsfrmDaily.form.dailyid,1)
    3
    ? left(forms!frmDailyEntry!sfcsfrmDaily.form.dailyid,1)=3
    True
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    I am trying to figure out a way to do it in the filter by form method. The user clicks filter my form and then enters a value in the box, which is numeric type.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Code:
    strFilter = "Left(FieldName,1) = " & Me.WantedNumber 
    Debug.Print strFilter
    Me.Filter = StrFilter
    Me.FilterOn = True
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    For FilterByForm use a query as form RecordSource.

    Calculate a field to convert number field to string. User can enter 72* and Access will change to LIKE 72*.

    I have never used FilterByForm in a deployed database. Would have to educate users on its use.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    add another field to the query where you convert the field to string: cStr([numField])
    then use your filter : like "72*" in THAT field.
    ni need to convert the number to text, just use

    like ‘72*’

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by CJ_London View Post
    ni need to convert the number to text, just use

    like ‘72*’
    There are those smart quotes again.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Okay, tested C.J. suggestion and it works on number field without converting to string in RecordSource. User has to know to enclose in apostrophes or quote marks (either works).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Autonumber now starts at 1
    By GordonT in forum Access
    Replies: 4
    Last Post: 08-29-2017, 07:17 AM
  2. Series number always starts at 1
    By trident in forum Reports
    Replies: 0
    Last Post: 04-14-2016, 02:18 AM
  3. Replies: 12
    Last Post: 12-03-2013, 10:31 AM
  4. Replies: 1
    Last Post: 11-30-2011, 11:02 AM
  5. How to add ID 1 above table that starts with ID 2 ?
    By Plomo in forum Database Design
    Replies: 2
    Last Post: 09-03-2009, 12:19 PM

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