Results 1 to 13 of 13
  1. #1
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85

    Ensuring user places the date and time in a date field

    Hello all. I am building a database for a non-profit to help them track classes they provide to community members. I have a table called ClassTable that has a field called SessionDate that is used to record the date and time of a class. Is there anyway to force the user to include the time in the field along with the date. For example, if the user places the date 12/1/2018 in the field and then tries to move on he/she would be advised that he/she must include a time with the entry. I tried coding using the len function, with the following code on the AfterUpdate event:
    If SessionDate.Value <> Null Then
    If Len(SessionDate) < 12 Then
    MsgBox "You need to include the time of the meeting also", vbOKOnly
    Else
    End If
    End If
    (I used the "<12" because if determined that the maximum date with out a time would still be less than 12 characters long)




    but this didn't work. I thought there might be a way to use a "mask" on the field properties but I'm not having any success.

    Any ideas?

    Thanks for the help.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you show the user an example of how to complete the field? What is the field data type BTW?

  3. #3
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    The data type on the field is Date. I will show the user how to complete the field but it has been my experience that sometimes you need to force the user to do things correctly even when you have given them instructions. I want the date field to include the time because the user will print out a document for the student showing the date and time of the class. I know I can use two date fields, one masked for the date and the other masked for the time but I'm trying to keep the number of fields in the table small.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you considered using two Text unbound Controls, one for the date and one for the time and then put them together for the actual field after verification.

  5. #5
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I was hoping to keep it simple.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    And still use people?? Simple for them or simple for you? I agree that you need to verify that both values are valid.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Further to Allan's advice, letting the user select a value(s) from a list(s) is less prone to input errors/typos than having them type in values.
    You can still verify selections before committing the record/update.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is speed of data entry important? If so, then just typing is faster but you may sacrifice some accuracy.

  9. #9
    Join Date
    Apr 2017
    Posts
    1,681
    Setting date control format as short date and time allows user enter date and time in same field. I myself prefer to set the according table field in same format too.

    Create a BeforeUpdate event for your form. The event must control, is date control value in form an integer (a date at 0:0:0 was entered) or not (a date with non-zero hours was entered). Depending on check results, and on your preferences:
    a) Updating of record is canceled (with message for user displayed), or not;
    b) When date control value was an integer, the user gets a message, and is given a choice, to save record, or to abort the update.

  10. #10
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    "Simple for them or simple for your?" Yes and Yes. It has been my experience that many people make (unintentional) mistakes when using a computer and so I like to keep the things I write as simple as possible which often includes limiting their choices or, failing that, advising them when they have done something wrong and providing information on how to do it correctly (which is the case here). I also know that in the future I may not be the one to have to fix or modify the program I am writing (I refer to my approach as the "if I get hit by a bus" protocol) and I want to try and keep the programmatic part as simple as possible. That means tables and fields that are clearly defined and programmatic elements (code) that is also as simple as possible. In this case I am hoping there is a "mask" element I am unaware of or a few lines of code that can be placed in an event that can advise the user of the requirement that a date and time must be entered in the appropriate field..

  11. #11
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    Thanks for the advice but I'm not experienced enough to do that. I understand the concept and wonder if the event could be tied to the control instead of the form. For example, use the AfterUpdate event for the field.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  13. #13
    Join Date
    Apr 2017
    Posts
    1,681
    Quote Originally Posted by Roncc View Post
    ...wonder if the event could be tied to the control instead of the form. For example, use the AfterUpdate event for the field.
    Yes, it could! Why I'd prefer Form event:

    When you use AfterUpdate event of date control, Access will check validity every time user edits the control entry, and take according actions - even when user him/herself would correct the entry otherwise. You have to write the code to clear the entry. You can't allow the user to accept the entry without hours - otherwise there may be repeating messages which will confuse user. And you must have BeforeUpdate event for form anyway - to prevent saving the record with empty date control - or you have to restrict saving otherwise when date control is empty for any possible scenario.;
    When you use BeforeUpdate event of form, user can edit the date control as many times as he/she wants. Validity checking is made once - when user moves to next record, checks Save from menu, presses Save Hot Key, etc. And the code not to save is simplest you can imagine - CANCEL (plus calling a message)! As result, the record remains unsaved, and the form is restored in state before user initiated saving.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2018, 04:58 PM
  2. Replies: 3
    Last Post: 04-27-2018, 03:57 AM
  3. Replies: 6
    Last Post: 04-19-2016, 03:58 PM
  4. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  5. Subtracting a date/time field from a number to get date/time
    By Lifeseeker1019 in forum Programming
    Replies: 4
    Last Post: 03-28-2014, 12:59 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