Results 1 to 4 of 4
  1. #1
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79

    Error By Manually Changing Dates in Textbox (OnChange)

    Hey,

    So I'm working on a form that aims to automatically display records based on the values of two textboxes. The textboxes are defined as dates, so the little calendar icon will pop up when you click into it. Some users prefer to type their date rather than use the calendar.

    Here's where I go wrong. I have an Event Procedure OnChange that defines and SQL Query and defines the "date range" of the SQL Query using the values in the textbox. When the user deletes the current value in textbox, this causes errors when the code automatically tries to run this SQL Query. For example: the default value of the textbox is Date(). The user wishes to change the day so they naturally click into the day portion of the date and hit backspace to clear the day. When they clear the day, the textbox reads "01//2017" (or something similar). When the SQL Query attempts to open a recordset using that date range I get a syntax error because #01//2017# is not a valid date.

    Is there a better way to do this and am I approaching this problem in the right way? I've looked into validation rules/text, but I don't have a strong grip on it. So I figured I'd post here to see if anyone had some insight.

    Thank you.

  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,642
    Use the after update event rather than the change event, which fires with every keystroke.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79
    Thank you! I'll try this out.
    Does the on update event trigger upon the user pressing Enter or anything like that? I guess my real question is what is an "update"?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    "Update" would happen after something has been typed in AND after it has been given to Access, i.e. moving out of that field by clicking or pressing enter/tab. Purely typing in a textbox is a visual thing, you see it but Access does not. Once you get out of that control (textbox or ...) then the information is given to Access - that is when the Update event is fired. (NOTE: it is not the underlying record on the table that has been updated, only the temporary space that Access uses for each individual field on the form. It is the form's AfterUpdate that happens after the table has been updated.)

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

Similar Threads

  1. Replies: 12
    Last Post: 12-10-2013, 08:57 PM
  2. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  3. Replies: 8
    Last Post: 05-16-2012, 10:49 AM
  4. Replies: 1
    Last Post: 07-28-2011, 09:30 AM
  5. Manually changing attribute
    By michaeljohnh in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:50 PM

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