Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

How can I intercept and modify the system warning message

Question posted by: kcdoell (Familiar Sight) on March 25th, 2008 04:18 PM
Hello:

I have a continuous form where the user can add records. One of the fields “Binding_Percentage” is a required field, so if left blank the user will receive the following message:

“The field ‘tblAllForecast.Binding_Percentage” cannot contain a Null value because the required property for this field is set to True. Enter a value in this field.”

I would like to customize this message so that it is more meaningful to the End User. How would I go about doing that via VB?

Any help would be appreciated.

Keith.
Last edited by kcdoell : March 25th, 2008 at 04:25 PM. Reason: Added detail
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
kcdoell's Avatar
kcdoell
Familiar Sight
230 Posts
March 27th, 2008
02:01 PM
#2

Re: How can I intercept and modify the system warning message
Any thoughts out there on this topic???

Reply
6360MGrist's Avatar
6360MGrist
Newbie
5 Posts
March 28th, 2008
03:07 PM
#3

Re: How can I intercept and modify the system warning message
Hi there,

Not sure if this is what you're after, but in the properties of the text box in the Validation Text Box you could type your message to your user, like this

Validation Rule : Is not Null
Validation Text : Please Enter A Value


This would then throw up a warning box with your personal message. Hope this helps.

Mark

Reply
Scott Price's Avatar
Scott Price
Moderator
1,303 Posts
March 28th, 2008
03:35 PM
#4

Re: How can I intercept and modify the system warning message
Alternatively a strict VBA solution would require you to set the warnings false before the error occurs, then in your error trapping mechanism calling a message box with your custom error message.


Regards,
Scott

Reply
kcdoell's Avatar
kcdoell
Familiar Sight
230 Posts
March 28th, 2008
06:14 PM
#5

Re: How can I intercept and modify the system warning message
Scott:

I would like to use your idea but never tried it before. Below is my code that executes when a new record is created. :

Code: ( text )
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. 'When a user is creating a new record the following code inserts the MonthID, YearID and
  3. 'The LocationsID.  It does a Dlookup for the Locations ID when the control cboLocation is
  4. 'blank.
  5.  
  6. Dim frm As Form
  7.  
  8. Set frm = Forms!Forecast
  9.  
  10. If Me.NewRecord Then
  11.   'If cboLocation is Not Null, grab the value from there
  12.   If Not IsNull(frm![cboLocation]) Then
  13.     JtnLocationsID = frm!cboLocation
  14.     YearID = frm!CboYear
  15.     MonthID = frm!CboMonth
  16.   Else      'Forms!Forecast![cboLocation] is Null
  17.     'Check and see if all 3 Controls have values in them
  18.     If Not IsNull(frm![cboDivision]) And Not IsNull(frm![cboWrkReg]) And _
  19.        Not IsNull(frm![cboCreditReg]) Then       'values in all 3 Controls
  20.          JtnLocationsID = DLookup("[JtnLocationsID]", "tblLocationsMM", "[DivisionIDFK] =" & frm![cboDivision] & _
  21.                           " And [WrkRegIDFK] =" & frm![cboWrkReg] & " And [CreditRegIDFK] =" & _
  22.                           frm![cboCreditReg])
  23.          YearID = frm!CboYear
  24.          MonthID = frm!CboMonth
  25.     Else
  26.       'no value in [cboLocation], and 1 or more values are missing in [cboDivision],
  27.       '[cboWrkReg], or [cboCreditReg]
  28.      
  29.       MsgBox "1 or more values are missing in"
  30.      
  31.     End If
  32.   End If
  33. End If
  34. End Sub


The control that is required on my form is called "Binding_Percentage". Where would I incorporate and "error catch" and what would be the verbiage in vb?

Any help would be great.

Thanks for the reply,

Keith

Reply
Scott Price's Avatar
Scott Price
Moderator
1,303 Posts
March 28th, 2008
06:59 PM
#6

Re: How can I intercept and modify the system warning message
It would be a good idea for you to read through some threads dealing with error handling in VBA. This is a link to Allen Browne's page on error handling. I personally use his error logging code.

However, to give you a brief overview:

On line 2 of your code you will have something like this:

Code: ( text )
  1. On Error GoTo Err_Form_BeforeUpdate


At the end of your code block (just before the End Sub) you'll have:

Code: ( text )
  1. Exit_Form_BeforeUpdate:
  2. Exit Sub
  3. Err_Form_BeforeUpdate:
  4. MsgBox Err.Description & " " & Err.Number, vbCritical
  5. Resume Exit_Form_BeforeUpdate


Obviously you can make the MsgBox say anything you want, including setting it's title, etc... There really isn't any need to set the warnings false, since this will suppress the default error message by itself, however, for future information the command to do so is:

Code: ( text )
  1. DoCmd.SetWarnings = False


Don't forget to set them on again before you exit the sub routine:

Code: ( text )
  1. DoCmd.SetWarnings = True


Regards,
Scott

Reply
isoquin's Avatar
isoquin
Member
48 Posts
March 28th, 2008
07:09 PM
#7

Re: How can I intercept and modify the system warning message
First I'll say I'm by no means an Access expert, but I have encountered this and came up with my own solution.

You can have your form's "BeforeUpdate" event check for the field first.
Code: ( text )
  1. if isNull(myVariable) Then
  2.    MsgBox ("your own error here")
  3.    Cancel = True
  4. Else: Cancel = False
  5. End If


Again, I'm no expert like some of the other pros here, but giv eit a shot.

Last edited by Scott Price : March 29th, 2008 at 12:21 AM. Reason: fix code tag
Reply
kcdoell's Avatar
kcdoell
Familiar Sight
230 Posts
March 28th, 2008
07:42 PM
#8

Re: How can I intercept and modify the system warning message
Thanks I will try that and get back to you both.

Keith.

Reply
kcdoell's Avatar
kcdoell
Familiar Sight
230 Posts
March 28th, 2008
08:07 PM
#9

Re: How can I intercept and modify the system warning message
Both ideas worked great!

Thank you,

Keith.

Reply
Scott Price's Avatar
Scott Price
Moderator
1,303 Posts
March 29th, 2008
12:21 AM
#10

Re: How can I intercept and modify the system warning message
Good call Isoquin! The reason to use the BeforeUpdate event in the first place is for data validation, which includes whether required fields are left blank.

Testing for a null value is 'best practice' :-) In addition to error handling for unexpected occurrences.

Glad it's working for you!

Regards,
Scott

Reply
Reply
Not the answer you were looking for? Post your question . . .
173,514 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Microsoft Access / VBA Forum Contributors