A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Prompt msge re input to mandatory field



 
 
Thread Tools Display Modes
  #1  
Old December 7th, 2006, 08:57 AM posted to microsoft.public.access.forms
CW
external usenet poster
 
Posts: 701
Default Prompt msge re input to mandatory field

I have a handful of mandatory fields on an input form and every now and then
a user will overlook one or another of them.

The resulting error message is (a) non-specific and (b) later than it should
be.

(a) All it says is "The value you entered is not valid for this field. For
example, you may have entered text in a numeric field or a number that is
larger than the Field Size setting permits".
It doesn't refer to any particular field, the cursor isn't flashing in the
problem area, the user has to work out where the problem may be.
Is it possible to re-word this error msge text or in some other way, tell
the user where the problem lies?

(b) The message is displayed only when you try to save the record. It would
be far better if it was fired as soon as you tried to leave the particular
field. I assume this would require some sort of code in an event such as On
Update, Lost Focus, or similar...

I would appreciate any tips on either/both the above points that would help
me make this rather more user-friendly.
Thanks a lot
CW
  #2  
Old December 7th, 2006, 02:54 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Prompt msge re input to mandatory field

You cannot just use the events of the control, because there is no guarantee
the user will ever visit the control.

Instead, use the BeforeUpdate event of the form. This fires before any
engine-level messages, so you can code whatever message you want.

Here's an example of how to check several controls, build up a message, and
park the cursor in the last one you referred to:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim strField As String

If IsNull(Me.Field1) Then
Cancel = True
strMsg = strMsg & "Field1 is required." & vbCrLf
strField = "Field1"
End If

If IsNull(Me.Field2) Then
Cancel = True
strMsg = strMsg & "Field2 is required." & vbCrLf
strField = "Field2"
End If

'etc for other fields

If Cancel Then
strMsg = strMsg & vbCrLf & "Correct the entry, or press Esc to
undo."
MsgBox strMsg, vbExclamation, "Invalid data"
Me(strField).SetFocus
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"CW" wrote in message
...
I have a handful of mandatory fields on an input form and every now and
then
a user will overlook one or another of them.

The resulting error message is (a) non-specific and (b) later than it
should
be.

(a) All it says is "The value you entered is not valid for this field. For
example, you may have entered text in a numeric field or a number that is
larger than the Field Size setting permits".
It doesn't refer to any particular field, the cursor isn't flashing in the
problem area, the user has to work out where the problem may be.
Is it possible to re-word this error msge text or in some other way, tell
the user where the problem lies?

(b) The message is displayed only when you try to save the record. It
would
be far better if it was fired as soon as you tried to leave the particular
field. I assume this would require some sort of code in an event such as
On
Update, Lost Focus, or similar...

I would appreciate any tips on either/both the above points that would
help
me make this rather more user-friendly.
Thanks a lot
CW



  #3  
Old December 8th, 2006, 03:45 PM posted to microsoft.public.access.forms
CW
external usenet poster
 
Posts: 701
Default Prompt msge re input to mandatory field

Allen -
That looks great, I'll give it a try. Many thanks for your (as always) clear
and complete advice.
CW

"Allen Browne" wrote:

You cannot just use the events of the control, because there is no guarantee
the user will ever visit the control.

Instead, use the BeforeUpdate event of the form. This fires before any
engine-level messages, so you can code whatever message you want.

Here's an example of how to check several controls, build up a message, and
park the cursor in the last one you referred to:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim strField As String

If IsNull(Me.Field1) Then
Cancel = True
strMsg = strMsg & "Field1 is required." & vbCrLf
strField = "Field1"
End If

If IsNull(Me.Field2) Then
Cancel = True
strMsg = strMsg & "Field2 is required." & vbCrLf
strField = "Field2"
End If

'etc for other fields

If Cancel Then
strMsg = strMsg & vbCrLf & "Correct the entry, or press Esc to
undo."
MsgBox strMsg, vbExclamation, "Invalid data"
Me(strField).SetFocus
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"CW" wrote in message
...
I have a handful of mandatory fields on an input form and every now and
then
a user will overlook one or another of them.

The resulting error message is (a) non-specific and (b) later than it
should
be.

(a) All it says is "The value you entered is not valid for this field. For
example, you may have entered text in a numeric field or a number that is
larger than the Field Size setting permits".
It doesn't refer to any particular field, the cursor isn't flashing in the
problem area, the user has to work out where the problem may be.
Is it possible to re-word this error msge text or in some other way, tell
the user where the problem lies?

(b) The message is displayed only when you try to save the record. It
would
be far better if it was fired as soon as you tried to leave the particular
field. I assume this would require some sort of code in an event such as
On
Update, Lost Focus, or similar...

I would appreciate any tips on either/both the above points that would
help
me make this rather more user-friendly.
Thanks a lot
CW




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:02 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.