issue

P

pat

I have a form imbedded within a main form, the sub form
is formatted as datasheet display. within this sub form
is a field which is a yes/no field, if the field is
is "yes" then i require that another field within the
record must be filled out (ie non blank) or the record is
not to be updated or saved. otherwise it can be blank.


I am not sure how to ensure this.

pat
 
J

John Vinson

I have a form imbedded within a main form, the sub form
is formatted as datasheet display. within this sub form
is a field which is a yes/no field, if the field is
is "yes" then i require that another field within the
record must be filled out (ie non blank) or the record is
not to be updated or saved. otherwise it can be blank.


I am not sure how to ensure this.

pat

Use the Form's (the form you're using in the subform) BeforeUpdate
event, e.g.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!chkYesNoField Then ' is the yes/no field Yes?
If IsNull(Me!OtherField) Then
MsgBox "Please fill in OtherField", vbOKOnly
Cancel = True ' cancel the update
Me!OtherField.SetFocus
End If
End If
ENd Sub

John W. Vinson[MVP]
 
P

Patrick Stubbin

Thankyou, this has now solved one issue and generated a second,

how do i stop data entry in that field if the yes/no is "NO"

thanks in anticipation,

ps: am mucking about trying things to solve this
 
P

Patrick Stubbin

UNLESS u have a neater solution to this i managed t fix it thanks


pat (i refer to my second posting) not the one below
 
K

Klatuu

Pat,
I added the logic you need to keep the user from entering data in the other
fields.
You will also need to add a line somewhere in your form to unlock OtherField
before you start your next record. I also added to the logic to check for an
empty string as well as a null. This will sometimes fool you and give
incorrect results.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!chkYesNoField Then ' is the yes/no field Yes?
If IsNull(Me!OtherField) or Me!OtherField = ""Then
MsgBox "Please fill in OtherField", vbOKOnly
Cancel = True ' cancel the update
Me!OtherField.SetFocus
Else
Me!OtherField.Locked = True
Me!NextFieldAfterOther.SetFocus
End If
End If
ENd Sub
 
Top