Check boxes and new record button

F

fossy

hello all,
On my form I have 2 check boxes and a new record button. I need the
user to check one of the boxes for sure (but only one), and if it doesn't the
button will not work...
Can anyone help me with this code

Thanks. Saul.
 
J

Jack Leach

Write a little Sub to handle the button, and call if from the FormCurrent
event, and the change event of each check box.

Private Sub Form_Current()
Call HandleButton
End Sub

Private Sub Check1_Change()
Call HandleButton
End Sub

Private Sub Check2_Change()
Call HandleButton
End Sub

Private Sub HandleButton()
'Check for both check boxes checked
If Me.Check1 And Me.Check2 Then
Me.ButtonNewRec.Enabled = False

'Check for one or the other
Else If Me.Check1 Or Me.Check2 Then
Me.ButtonNewRec.Enabled = True

Else
'None Checked
Me.ButtonNewRec.Enabled = False
End If



You might need to add null handling... not sure without testing it.

hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
D

Dale Fye

Personally, if you want someone to check one, and only one checkbox, I'd
change them to radio buttons and put them inside an option group. Set the
default value of the group to 0, and the value of the buttons to 1 and 2.

Then, set the command buttons enabled property to False

Finally, in the option groups AfterUpdate event, set the enabled property of
the command button to True if the value of the option group <> 0

As an alternative to the Option Group, you could put a little code in the
Click event of each of the checkboxes, similar to the one below. Assuming
the two checkboxes are named check11 and Check13, then this code would ensure
that no more than one of these two checkboxes is checked at a time, and would
enable the command button if either checkbox is checked.

Private Sub Check11_Click()

If Me.Check11 = True Then Me.Check13 = False
Me.Command6.Enabled = Me.Check11 Or Me.Check13

End Sub

Private Sub Check13_Click()

If Me.Check13 = True Then Me.Check11 = False
Me.Command6.Enabled = Me.Check11 Or Me.Check13

End Sub
 
F

fossy

Jack thanks alot for the help... this is what i did

Private Sub btnNEW_Click()
On Error GoTo Err_btnNEW_Click

'check for no box checked
If Me.Press_Chk_Partial = False And Me.Press_Chk_Complete = False Then
MsgBox ("Please selecet Partial or Complete")

Exit Sub

'Check for Both
ElseIf Me.Press_Chk_Partial = True And Me.Press_Chk_Complete = True Then
MsgBox ("Please select only one Partial and Complete")
Exit Sub

'Check for one or other
Else:
GoTo DoCommand

End If

DoCommand:
DoCmd.GoToRecord , , acNewRec

Exit_btnNEW_Click:
Exit Sub

Err_btnNEW_Click:
MsgBox Err.Description
Resume Exit_btnNEW_Click

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