Custom error message based on two sets of criteria

M

Mr-Re Man

I was hoping someone could provide me with a snippet of code so that I can at
last get a form to work correctly.

I have a "check box" called "Staff_Required" to represent yes and no, and a
box called "No_of_staff" that allows a number to be input.

I have already set up the form so that if the "Staff_Required" check box has
a tick the "No_of_staff" box is displayed, and likewise, if no tick is in the
box, the "No_of_staff" box is not displayed.

What I require, if someone indicates by placing a tick in the
"Staff_Required" check box, is an error messgaae that prompts the user to
input a number if they have left the "No_of_staff" box blank or to input a
number if they enter a negative value or zero. check box.

I'm sure this is very simple, I have tried a few alternatives from this
forum, but sadly failed.
 
L

Linq Adams via AccessMonster.com

This will set the visibility appropriately:

Private Sub Form_Current()
If IsNull(Me.StaffRequired) Or Me.StaffRequired = 0 Then
No_of_staff.Visible = False
Else
No_of_staff.Visible = True
End If
End Sub

Private Sub StaffRequired_AfterUpdate()
If Me.StaffRequired = -1 Then
No_of_staff.Visible = True
Else
No_of_staff.Visible = False
Me.No_of_staff.Value = Null
End If
End Sub
 
L

Linq Adams via AccessMonster.com

Sorry, forgot about your final requirement! To check that a value is entered
in No_of_Staff if StaffRequired is checked:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.StaffRequired = -1 And (IsNull(Me.No_of_staff) Or Me.No_of_staff = 0)
Then
Cancel = True
No_of_staff.SetFocus
MsgBox "If StatffRequired is Checked, a Number Must Be entered in Nunber of
Staff Required Field"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top