Need help with an input mask on a form

greaseman

Closer to seniority!
Local time
Today, 02:47
Joined
Jan 6, 2003
Messages
360
I have a form that contains text boxes for inputting a date and one for inputting a time. Ive got the date box doing great with calendar control. What I need help with is setting up an input mask for the time box in such a way that the user doesn't have to worry about putting in colons to separate the hours, minutes and seconds. I want the user to just be able to enter, for example, "6', hit the tab key, enter "10" , hit the tab key, enter "P" or "A" ("610P") and then go on their merry way. Does anyone have an example of this, or a suggestion?

Related to my brain-dead plight, what might be a good way to validate a correct/incorrect time entry? Our tables do not use military time.

You folks are great! Can't wait until I feel comfy enough to start feeding back some suggestions to this forum and in turn help others!

Thanks!
 
there's an input mask already built for you called medium time.

99:00 >LL;0;_
 
Input mask for a time field

Thank you for your fast reply! :p That's very close to what I had intended. Just one question..... if the user types in something like 6 for the hour instead of 06, an error message pops up, saying the format isn't what was expected. Is there an input mask (or code or a function) that handles that kind of thing?

Again, thank you for your help!
 
Try 00:00 >LL;0;_

The zeros will force a number, the nines make it optional which is causing your problem.
 
Input mask headaches

And... thank you for your reply! But...... what I'm looking for and perhaps the input mask isn't the right thing, is :

A user enters something like 610P for a time. with the suggested input mask, they still would have to enter the time as 06 for the hour (or minutes), because if they just enter 6 and tab to the minutes, , the entry becomes 60:00 and an error pops up complaining about an improper format. Would I be better off writing some code to "flip" numbers and so forth?

Your interest and help are very appreciated. Thank you again!
 
I know this is not a solution to your true query, but could you not use a drop down box?
 
Input masks for time fields

Most likely, the users would scream..... they want only to put in a number and the letter "A" or "P" and have the program do the rest for them "by magic."

Thanks for the suggestion! That's what I said earlier about people in this forum. Willing to help and willing to listen.
 
just whipped this up. you can tinker with it.

PHP:
Private Sub TimeBox_Exit(Cancel As Integer)
TimeBox = Replace(Me.TimeBox, " ", "")
Select Case Len(TimeBox)

Case 5
Me.TimeBox = MakeTime(TimeBox, 5)

Case 6
Me.TimeBox = MakeTime(TimeBox, 6)
Case Else
MsgBox "Incorrect time format. Must be 00:00 XX"
Me.TimeBox = Null



End Select

End Sub

Public Function MakeTime(TheTime As String, XLength As Integer) As String

If XLength = 5 Then
x = 1
Else
x = 2
End If


boxtime = Me.TimeBox
boxtimeL = Left(boxtime, x)
boxtime = boxtimeL & ":" & Right(boxtime, Len(boxtime) - x)

prefix = Left(boxtime, Len(boxtime) - 2)
suffix = UCase(Right(boxtime, 2))


MakeTime = prefix & " " & suffix



End Function

on my test form, I used on exit because it was unbound, but you'd probably want to use before update event on yours.
 
Format for Time"

Wow! That was nice of you! I'll give it a go and let you know what happens. Who'd have thought that Microsoft hasn't addressed itty bitty things like this? Oh well......

Thanks again. And even if it doesn't work, just the idea that your'e willing to help is appreciated.
 
well, I saw you were from San Antonio and said to myself, "Self! I know some one down there, and by the off chance they know eachother, I should do something to help" :) lol, hope it works out. You can add more trapping to it, that was just a basic one.

Also, you should take the time to change the variable names. I used variants in there where things could be explicitly typed as strings etc. I'm just so used to ASP and in ASP, everything is variant.
 
Last edited:
Small world, isn't it? San Antonio's a great place, but technology-wise, kinda behind, compared to Boston or San Jose. Thanks again for the help!
 
Kodo,

I hate to be a pain, but I noticed you used a "Replace" function at the top of your code. I'm running Access 97, and didn't see that function. Is there an equivalent ACC 97 function for that? Or maybee....some code?

Trying not to take the proverbial mile given an inch.....

Thanks!
 
Perhaps if you had a popup form that allowed the user to select a data and a time? This sample will do just that. Popup Calendar - Version 3

You have to be a member of the UtterAccess forum to download the samples from their code archives section of the forum.
 
this should fix that provided SPLIT works in 97..

PHP:
Private Sub TimeBox_Exit(Cancel As Integer)
'TimeBox = Replace(Me.TimeBox, " ", "")
TimeBoxarr = Split(Me.TimeBox, " ")
For i = 0 To UBound(TimeBoxarr)
NewString = NewString & TimeBoxarr(i)
Next
TimeBox = NewString

Select Case Len(TimeBox)

Case 5
Me.TimeBox = MakeTime(TimeBox, 5)

Case 6
Me.TimeBox = MakeTime(TimeBox, 6)
Case Else
MsgBox "Incorrect time format. Must be 00:00 XX"
Me.TimeBox = Null



End Select

End Sub
 
Thanks! "Utter"-ly interesting....I'll check it out!
 
Nope..... "SPLIT" isn't in Acc 97. That's OK - I'm working on a little code that uses the "InStr function.

My biggest problem is that I just got handed two more projects that (Murphy's law) are due by the end of this week, as is this one, and I've got several "higher-ups" hammering me. I'm sure your'e familiar with the scene.

Thanks for all your help today..... enjoyed it.
 
good god, wtf DOES acc97 do.. any chance of upgrading? it'll make life that much easier when bombs get dropped on you..
 
ACC 97 is pretty good in its own way. It looks like a bunch of its shortcomings were taken into account for higher releases of access. Most likely, Microsoft visited the Access forums and saw what folks were doing to "work around" its irritations, and then incorporated those things that folks had already invented.

As a rule, I've had to develop VBA workarounds for many things in Acc 97, since Acc 97 seems to have a lot of "You can't get there from here."

In any case, as long as the users keep thinking of you as a "god," when it comes to Acc 97, then all is well in the world and voila! you have a job!

Our company is kinda archaic, and has been saying they're going to upgrade. But..... that's all it's been for 12 or so months now. It's one of the reasons I just landed a new job with a new company (I start on Monday) that seems more progressive. I'll still definitely be using this forum, though - it's been a lifesaver more often than not!
 

Users who are viewing this thread

Back
Top Bottom