Form Validation Problem

hwong

Registered User.
Local time
Today, 09:13
Joined
Jul 20, 2012
Messages
10
Greating all!

I have been requested to create a form for entering 1) Sex 2) Number of Pregnancy 3) ...

How can I prohabit the user to enter value into 2) Number of Pregnancy if answer of 1) is Male :banghead:

I have tried hundred times and still no idea X(

Anyone would like to help this lost sheep?

Thanks X 100!
 
Welcome to the forum.

In the On Click event of your Sex field some code along the lines of;

Code:
If Me.[COLOR="Red"]YourSexField[/COLOR] = [COLOR="Purple"]"Male"[/COLOR] Then
     Me.[COLOR="Red"]Pregnancy[/COLOR].Locked = True
     Me.[COLOR="Red"]Pregnancy[/COLOR].Enabled = False
Else
     Me.[COLOR="Red"]Pregnancy[/COLOR].Locked = False
     Me.[COLOR="Red"]Pregnancy[/COLOR].Enabled = True
End If

This code will also need to appear in the Form's On Current event. The Red highlighted sections will need to be changed to reflect the reality of your DB.

The purple highlighted section will need to be changed also depending if the field YourSexField is a text or numeric value.
 
Welcome to the forum,

You can set some VBA code behind the Combo Box and if Value selected is Male then txtPregancy.locked. sample code: Also empty the value in the how many times pregant incase they place a number in there first.

Private Sub Gender_AfterUpdate()
If Me.Gender.Value = "Male" Then
Me.Pregancy.Value = Null

Me.Pregancy.Locked = True

Else
Me.Pregancy.Locked = False
End If


End Sub
 
If you have a male entering his number of pregnancies then you have a bigger problem :D
 
After trial and error of John and Trevor's code, it is successful at the end. Thanks.

My default choices are "MALE" or "FEMALE", and I have tried and failed thousand times by using "Male" in setting the code......XD
 

Users who are viewing this thread

Back
Top Bottom