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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button Verifies that one of two check boxes are ticked 3

Status
Not open for further replies.

metalboy

Technical User
Joined
Apr 1, 2004
Messages
97
Location
GB
Is it possible for a command button to check that one of two check boxes are ticked before continuing to submit a form?

Regards

Alex
 
Hope this is what you mean:

Private Sub Command6_Click()
'Check one of boxes are ticked
If Check0.Value = -1 Or Check1.Value = -1 Then
.... code to submit form ....
Else
MsgBox ("Both boxes empty")
End If
End Sub
 
I assume that you are talking about saving a record. 'Submit' buttons don't have much context in an Access form.

If you are clicking a 'Save Record' button that you have added using the wizard (or some other way ) then you can add code to the procedure that has been created.
This should go around the save statement.

if me!checkbox1 = true or me!checkbox2 = true then
.........save statement here......
Else
msgbox "Please choose one or more option"
end if

You need to use your own checkbox nanes and put a sensible message into the msgbox.


 
I am getting the following error:

runtime error 424 object required

With the followng code

Code:
Private Sub Submit_Click()

If cancelled.Value = -1 Or verifed.Value = -1 Then
  DoCmd.GoToRecord , , acNext
   DoCmd.Close acForm, "Crosby Call logging"
   DoCmd.OpenForm "Start"
Else
    MsgBox ("Cancelled Or Verified Must Be Selected")
End If
End Sub

thank you
regards

Alex
 
If cancelled.Value = -1 Or verifed.Value = -1 Then


Regards

Alex
 
This suggests that your check box names aren't really 'Cancelled' and 'Verified'.

You can also remove the 'goto next' statement; the record will save when the form closes.
 
lupins your version works but i have mandatory fields on the form so if someone clicks on of the check boxes then hits save record it gives runtime error 2105 you cant go to the specific record and offers a debug button! how do i stop this??

thanks for your help

Regards

Alex
 
Hi

Use OnError to trap the error, give a sensible message to the user and cancel the update of the row

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Sorry i know this is probably very basic but where do i fit in that code?

Code:
Private Sub Submit_Click()

If Me!cancelled = True Or Me!verified = True Then
 DoCmd.GoToRecord , , acNext
   DoCmd.Close acForm, "Crosby Call logging"
   DoCmd.OpenForm "Start"
Else
MsgBox "Please choose one or more option"
End If

End Sub

thank you again for you continuing help

Regards

Alex
 
Hi!

Several ways, here's one suggestion:

[tt]Private Sub Submit_Click()
on error goto myerr
If Me!cancelled = True Or Me!verified = True Then
DoCmd.GoToRecord , , acNext
DoCmd.Close acForm, "Crosby Call logging"
DoCmd.OpenForm "Start"
Else
MsgBox "Please choose one or more option"
myexit:
exit sub
myerr:
if err.number<>2105 then
msgbox err.description
else
msgbox "fill out the required controls"
end if
resume myexit
End If
End Sub[/tt]

- typed not tested

KenReay - congrats on the Tipmaster Honour!

Roy-Vidar
 
Thank you everyone so much! you make learning a pleasure!

Regards

Alex
 
ok guys you are great and i need a little more help if possible. is it possible so the two check boxes are checked so that the only way that you can proceed is that only one of the boxes are ticked? so if both are false it shows a message box and if both are true it shows a message box??

Thank you all so much

Regards

Alex
 
Private Sub Submit_Click()
on error goto myerr
If Me!cancelled <> Me!verified Then
DoCmd.GoToRecord , , acNext
DoCmd.Close acForm, "Crosby Call logging"
DoCmd.OpenForm "Start"
Else
MsgBox "Please choose one and only one option"
myexit:
exit sub
myerr:
if err.number<>2105 then
msgbox err.description
else
msgbox "fill out the required controls"
end if
resume myexit
End If
End Sub


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thank you so much! I cannot say how helpful you all are!

Regards and best wishes

Alex
 
Hi Roy

Ref "KenReay - congrats on the Tipmaster Honour! "

Thanks for that

Regards

Ken Reay

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top