Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box checking ...

Status
Not open for further replies.

tinymind

Programmer
Nov 9, 2000
90
GB
Hello all ...

Simple problem ...

2 check boxes on a form that the user must select at least once ...

In the button a simple call procedure lets the form continue if the user has selected at least one of the check boxes ..

Btn code:

If CheckForm = False Then
Exit Sub
Else

Function code:

Public Function CheckForm() As Boolean

Dim db As Database

If Forms![Staff]![chkID] = 0 And Forms![Staff]![chkAgency] = 0 Then
CheckForm = False
Else
CheckForm = True
End If

End Function

Where am I going wrong ...??

Tiny...
 
If either of the check boxes are not set to False ( Ie. they are NULL), not having been set to anything, then you will always return the THEN result due to the 'Propogation of Null'

You need to set the default value on the checkbox control to False - rather than leaving it blank.


By the way - the easier / quicker way to code what you have put would be
Code:
Public Function CheckForm() As Boolean
CheckForm = Forms!Staff!chkID OR Forms!Staff!chkAgency
End Function


Which, in itself, provides an alternative solution to your problem
Code:
Public Function CheckForm() As Boolean
CheckForm = Nz(Forms!Staff!chkID,0) Or Nz(Forms!Staff!chkAgency,0)
End Function
Because then Null will be treated like False





'ope-that-'elps.

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top