By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

Better error messages for Input Masks

P: n/a
I'm working on a subform where users put in 24-hour time. On their
paper forms, they've been accustomed to referring to midnight as
24:00 (instead of as 0:00, which kind of makes sense from a human
point of view, though it's still wrong, as it puts midnight as the
end of the previous day instead of the beginning of the next, but it
avoids the zero time problem). I have an input mask to put the : in
the time, but when you input 24:00, it gives a fairly unhelpful
error message. I don't see an error number for this, so I was
wondering how I can trap for it, short of using OnChange.

Any ideas?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sun, 13 Jun 2004 22:53:15 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
I'm working on a subform where users put in 24-hour time. On their
paper forms, they've been accustomed to referring to midnight as
24:00 (instead of as 0:00, which kind of makes sense from a human
point of view, though it's still wrong, as it puts midnight as the
end of the previous day instead of the beginning of the next, but it
avoids the zero time problem). I have an input mask to put the : in
the time, but when you input 24:00, it gives a fairly unhelpful
error message. I don't see an error number for this, so I was
wondering how I can trap for it, short of using OnChange.

Any ideas?


I've given up on input masks entirely, but my solution isn't particularly
elegant. Use an unbound control for input/editing, and validate using only
VBA code it in the BeforeUpdate handler. The value must be copied to the
unbound control from the hidden bound control OnCurrent (reading values from
directly from fields not bound to controls is unreliable in Access 2000 and
above), and the value copied back to the bound control on AfterUpdate of the
unbound control.

If the form is continuous, stick the unbound control behind a locked/disabled
bound control (which can bu used in place of the hidden control above), and
place a transparent button (yes, I hear you saying aargh) on top of the whole
stack, so the user can set the focus to the unbound control by clicking.

You might have alreasy thought of this and discarded it as not worth the
trouble, buy it's the best I have to offer, I'm afraid. Back in the Access 2
days, I used the OnCurrent handler which, messy as it is, is cleaner than this
approach, but that was when you could write to the text property of the
control without Access insisting on trying to update the control's Value
immediately when you do this. I guess MS changed that behavior so as to be
less confusing to VB programmers, but it makes Access UI programming much less
flexible. That's one thing MS got right the first time, then promptly, and
permanently broke.
Nov 13 '05 #2

P: n/a
Steve Jorgensen <no****@nospam.nospam> wrote in
news:h1********************************@4ax.com:
On Sun, 13 Jun 2004 22:53:15 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
I'm working on a subform where users put in 24-hour time. On their
paper forms, they've been accustomed to referring to midnight as
24:00 (instead of as 0:00, which kind of makes sense from a human
point of view, though it's still wrong, as it puts midnight as the
end of the previous day instead of the beginning of the next, but
it avoids the zero time problem). I have an input mask to put the
: in the time, but when you input 24:00, it gives a fairly
unhelpful error message. I don't see an error number for this, so
I was wondering how I can trap for it, short of using OnChange.

Any ideas?
I've given up on input masks entirely, but my solution isn't
particularly elegant. Use an unbound control for input/editing,
and validate using only VBA code it in the BeforeUpdate handler.
The value must be copied to the unbound control from the hidden
bound control OnCurrent (reading values from directly from fields
not bound to controls is unreliable in Access 2000 and above), and
the value copied back to the bound control on AfterUpdate of the
unbound control.

If the form is continuous, stick the unbound control behind a
locked/disabled bound control (which can bu used in place of the
hidden control above), . . .


I can't do that -- it's a datasheet form.
. . . and place a transparent button (yes, I hear
you saying aargh) on top of the whole stack, so the user can set
the focus to the unbound control by clicking.
An awful kludge.
You might have alreasy thought of this and discarded it as not
worth the trouble, buy it's the best I have to offer, I'm afraid.
Back in the Access 2 days, I used the OnCurrent handler which,
messy as it is, is cleaner than this approach, but that was when
you could write to the text property of the control without Access
insisting on trying to update the control's Value immediately when
you do this. I guess MS changed that behavior so as to be less
confusing to VB programmers, but it makes Access UI programming
much less flexible. That's one thing MS got right the first time,
then promptly, and permanently broke.


Well, I could use the BeforeUpdate and evaluate the value entered
and then have a user-friendly error message (removing the input
mask, of course). But I'm not sure I want to give up the ease of use
and clear UI of the input mask that provides the colon in the times.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3

P: n/a
Hi David,

This seems like a "way to easy" one, and I apologize in advance if there is
more to it than what I understand ...

Private Sub txtTime_AfterUpdate()
Me.txtTime = Format(Me.txtTime, "00:00")
End Sub

Seems to work ...
enter "100", get "01:00"
enter 1300 , get 13:00
enter 13:00, get 13:00
.... etc

--
HTH,
Don
=============================
Use My*****@Telus.Net for e-mail
Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.90...
I'm working on a subform where users put in 24-hour time. On their
paper forms, they've been accustomed to referring to midnight as
24:00 (instead of as 0:00, which kind of makes sense from a human
point of view, though it's still wrong, as it puts midnight as the
end of the previous day instead of the beginning of the next, but it
avoids the zero time problem). I have an input mask to put the : in
the time, but when you input 24:00, it gives a fairly unhelpful
error message. I don't see an error number for this, so I was
wondering how I can trap for it, short of using OnChange.

Any ideas?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc

Nov 13 '05 #4

P: n/a
"Don Leverton" <le****************@telusplanet.net> wrote in
news:z%mzc.45654$%i1.40052@edtnps89:
This seems like a "way to easy" one, and I apologize in advance if
there is more to it than what I understand ...

Private Sub txtTime_AfterUpdate()
Me.txtTime = Format(Me.txtTime, "00:00")
End Sub

Seems to work ...
enter "100", get "01:00"
enter 1300 , get 13:00
enter 13:00, get 13:00


OK, and then I could have the BeforeUpdate catch 2400 or 24:00.

I'll see if it matters enough to try out (I need to do it in only
two fields, so it's not disastrous).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.