Results 1 to 5 of 5
  1. #1
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87

    Search field for Dates

    I have a form that I would like to have a combo box that I can do searches for the order date. Below is the code I am using for the AfterUpdate combo.

    Private Sub cboWholesaleDateSearch_AfterUpdate()
    If IsNull(cboWholesaleDateSearch) Then
    Me.FilterOn = False
    Else


    Me.Filter = "[WhlSleOrderID]=" & cboWholesaleDateSearch & ""
    Me.FilterOn = True
    End If
    End Sub


    When I enter or select the date in the search box I receive the message "The value you entered isn't valid for this field." I have the Format options set to Medium Date for both the search box and the text box in the main form. I am using the same code for several other search boxes on another form, however they are not searching for dates, but they work fine. Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If you want to filter on date, why is field searching in WhlSleOrderID and not a date/time field?

    Use # delimiter for date/time field parameter. Like:

    Me.Filter = "[yourdatefield]=#" & cboWholesaleDateSearch & "#"
    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.

  3. #3
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    Quote Originally Posted by June7 View Post
    If you want to filter on date, why is field searching in WhlSleOrderID and not a date/time field?
    When I was working on the code for the other form, if I had the field I was searching for listed, I would get a Run-Time error 3709. Another user suggested I use the OrderID field and that fixed the issue. I just used the same code and changed the fields. I should mention that for the Search boxes for the other form, I have the Row Source as a query with the OrderID and search item referenced.

    I made the changes you suggested. I tried adding the # delimiter and then changing from [WhlSleOrderID] to [WhlsleDate]. Received the same message.

    Private Sub cboWholesaleDateSearch_AfterUpdate()
    If IsNull(cboWholesaleDateSearch) Then
    Me.FilterOn = False
    Else
    Me.Filter = "[WhlsleDate]=#" & cboWholesaleDateSearch & "#"
    Me.FilterOn = True
    End If
    End Sub

    I also have the Row Source as the query with WhlSleOrderID and WhsleDate. I was thinking that as long as I establish Medium Date format in both the search box and also the date field in the form I would be fine. Apparently that's not the case.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    But you said you are searching for dates, not IDs.

    If your combobox value is ID, then your original code should work. If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  5. #5
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    I re-copied and pasted the code again and for some reason this time it worked. Thank you for your help.

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

Similar Threads

  1. How to search for subsequent dates in form
    By Beeblebrox in forum Programming
    Replies: 13
    Last Post: 04-28-2016, 10:14 AM
  2. Search by weeks and or months (dates)
    By sdc1234 in forum Access
    Replies: 3
    Last Post: 08-30-2013, 10:57 AM
  3. Replies: 3
    Last Post: 03-27-2013, 08:27 AM
  4. Search Query - Between Dates
    By AndreasPanayiotou in forum Queries
    Replies: 1
    Last Post: 09-10-2012, 07:06 AM
  5. Search for specific dates
    By natalia in forum Queries
    Replies: 2
    Last Post: 09-27-2010, 03:15 AM

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