Results 1 to 7 of 7
  1. #1
    Jxsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    2

    Time Entry with Input Mask

    I'm setting up an input form, and a couple of the fields are times. I want to set up the form so that a user can just type "453" to get 4:53, but no matter what I think of, Access always populates the field as 45:3_. I'm using a mask: 90:00, and I've tried including every variation of "!" that I can come up with.

    I'm new to Access, having previously used Excel & VBA for this sort of stuff, so nothing is intuitive.



    Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    You haven't said what you have tried but I believe input masks require a predetermined number of characters. See this link https://support.office.com/en-us/art...2-4a47832de8da

    You will need to train your users to input 0453

    if you are planning to use this value in a calculation of some sort note that time is stored as a decimal value - the number of seconds for the time divided by the number of seconds in the day (86400) so 4:53 will be

    ((4*60*60)+(53*60))/86400=0.203

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Input masks are often more of a nuisance than a help.

    If, as you should be, you are using a form to enter the time, I suggest you use the method found on most phones these days.
    Have two combos -hours with all values from 0 to 23 and minutes with 0 to 59.
    Then use code to combine and display as 04:53 etc
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    Jxsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    2
    Sorry, I think my original point was missed. I want Access to do what I want it to do, not change our functioning method of doing things to suit the program. If the solution to ‘train my users’ was acceptable then I could just do this in Excel.

    Am I really asking for something so unusual? Surely someone has needed to input numbers like this before: the user enters three or four digits, which results in a short time format.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I don't think your point was missed.
    Sometimes there are better ways of doing things than using input masks.
    Times are one such example
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Jxsmith View Post

    ...I want Access to do what I want it to do, not change our functioning method of doing things to suit the program...
    As any experienced programmer will tell you, regardless of the language being used, you have to work within the rules and native abilities of that language, unless you're willing to do custom programming, if the language allows! Fortunately, Access does allow for custom programming, and I think the only practical way of doing this is to do your formatting using the Control's AfterUpdate event.

    Something like this:

    Code:
    Private Sub TimeField_AfterUpdate()
     
     Select Case Len(Me.TimeField)
     
     Case 2
       
       Me.TimeField = ":" & Right(Me.TimeField, 2)
      
      Case 3
       
       Me.TimeField = Left(Me.TimeField, 1) & ":" & Right(Me.TimeField, 2)
     
      Case 4
       
       Me.TimeField = Left(Me.TimeField, 2) & ":" & Right(Me.TimeField, 2)
    
     End Select
     
    End Sub


    Note a couple of things about this approach:

    The Field will need to be redefined as Text...you cannot enter a series of digits into a Field defined as Date/Time...Access won't allow it.

    Because of this...in order to use the Field for calculations involving Time, you'll have to use Type Conversion, using CDate(Me.TimeField).

    Quote Originally Posted by Jxsmith View Post

    ...Surely someone has needed to input numbers like this before...
    Actually, I've been answering questions on this, and half a dozen other Access forums, for a dozen years, now, and have never seen anyone presenting with this need! But to each their own!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    If the solution to ‘train my users’ was acceptable
    just to be clear - what if the time is 4 hours dead - do you train users to enter 400 or are you expecting access to interpret this as 4 hours and not 4 minutes?

    you could create four controls, each one to accept a single character and in the onchange event automatically move to the next control

    I could just do this in Excel.
    As I'm sure you know, excel does not have input masks, but it does have custom formats - and you can use those to display an entry of 453 as 4:53 - just the same as Access. And as with excel, you will need code to convert that to date/time if you are going to use the value in a calculation. And you still need to train your users to enter 400 for 4 hours dead.

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

Similar Threads

  1. date/time input mask and date ordering
    By jsberry in forum Database Design
    Replies: 1
    Last Post: 06-19-2017, 01:04 PM
  2. Replies: 4
    Last Post: 05-02-2016, 04:23 PM
  3. Input Mask
    By warmanlord in forum Access
    Replies: 11
    Last Post: 10-15-2015, 10:01 AM
  4. Time Input mask - arrgh!
    By Sheba in forum Forms
    Replies: 1
    Last Post: 09-16-2014, 01:43 PM
  5. Input mask
    By scorpion99 in forum Access
    Replies: 4
    Last Post: 02-21-2014, 02:18 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