How do I check for two blank boxes on a form

G

Guest

How can I check in the same procdeure two seperate field boxes on a form.

I have 3 boxes.

The first is a tick box. If the user ticks it. How can I ensure that he
fills in the two blank boxes associated with the tick box.

If the user doesn't tick the box, then the two text fields can remain blank.
I can do it with one text filed, but not two.

Help!
 
B

Brendan Reynolds

If Me!NameOfCheckBox = True Then
If IsNull(Me!NameOfFirstTextBox) And IsNull(Me!NameOfSecondTextBox) Then
...
End If
End If

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
A

Allen Browne

Use the Before Update event procedure of the form to check if the other 2
boxes are Null when the check box is True.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.[Checkbox1].Value Then
If IsNull(Me.[Textbox1]) Or IsNull(Me.[Textbox2]) Then
Cancel = True
MsgBox "Must enter both values when boxes is checked."
End If
End If
End Sub
 
G

Guest

Guys,

Thanks for your help. My routine works to an extent. but assuming the
tick-box is 'Yes' it only checks if both fields are blank simultanesouly. The
problem is the user can fill-in one field but leave the other blank... any
ideas?


Allen Browne said:
Use the Before Update event procedure of the form to check if the other 2
boxes are Null when the check box is True.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.[Checkbox1].Value Then
If IsNull(Me.[Textbox1]) Or IsNull(Me.[Textbox2]) Then
Cancel = True
MsgBox "Must enter both values when boxes is checked."
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Veewhy said:
How can I check in the same procdeure two seperate field boxes on a form.

I have 3 boxes.

The first is a tick box. If the user ticks it. How can I ensure that he
fills in the two blank boxes associated with the tick box.

If the user doesn't tick the box, then the two text fields can remain
blank.
I can do it with one text filed, but not two.

Help!
 
A

Allen Browne

The code should force the user to enter both.

If you intended that the user must at least one (not necessarily both),
change the Or to an And:
If IsNull(Me.[Textbox1]) And IsNull(Me.[Textbox2]) Then

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Veewhy said:
Guys,

Thanks for your help. My routine works to an extent. but assuming the
tick-box is 'Yes' it only checks if both fields are blank simultanesouly.
The
problem is the user can fill-in one field but leave the other blank... any
ideas?


Allen Browne said:
Use the Before Update event procedure of the form to check if the other 2
boxes are Null when the check box is True.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.[Checkbox1].Value Then
If IsNull(Me.[Textbox1]) Or IsNull(Me.[Textbox2]) Then
Cancel = True
MsgBox "Must enter both values when boxes is checked."
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Veewhy said:
How can I check in the same procdeure two seperate field boxes on a
form.

I have 3 boxes.

The first is a tick box. If the user ticks it. How can I ensure that he
fills in the two blank boxes associated with the tick box.

If the user doesn't tick the box, then the two text fields can remain
blank.
I can do it with one text filed, but not two.

Help!
 

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

Similar Threads


Top