vb code in access to enable the checkbox

How to make vb code in access to enable the checkbox [accepted) if any or all of the following checkboxs [vbp] or [vbv] or [lhi] or [lwt] or [emr] is TRUE.
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
something like this:
if vbp.checked = vbChecked or vbv.checked = vbChecked or lhi.checked = vbChecked or lwt.checked = vbChecked or emr.checked = vbChecked then
accepted.checked = vbChecked
else
accepted.checked = vbUnChecked
end if 

Open in new window

0
 
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAuthor Commented:
Dear Guy
Thanks I tried the following but did give error message

Private Sub Acceptd_BeforeUpdate(Cancel As Integer)
If Vbp.Checked = vbChecked Or Vbv.Checked = vbChecked Or Lhi.Checked = vbChecked Or Lwt.Checked = vbChecked Or Emr.Checked = vbChecked Then
accepted.Checked = vbChecked
Else
accepted.Checked = vbUnChecked
End If
End Sub
error.png
0
 
mbizupCommented:
Try this, replacing the names I am using with your actual checkbox names:

 Me.chkaccepted = Me.Checkbox1 + me.Checkbox2 + Me.Checkbox3 + Me.Checkbox4    ' etcetera

Open in new window

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mbizupCommented:
The above will check a checkbox named chkAccepted.  If you want to enable it:

Me.chkaccepted.enabled = Me.Checkbox1 + me.Checkbox2 + Me.Checkbox3 + Me.Checkbox4    ' etcetera

Open in new window


This will enable chkAccepted if any are true, and disable it if all are false.
0
 
mbizupCommented:
>> Private Sub Acceptd_BeforeUpdate(Cancel As Integer)

Just noticed this... The BeforeUpdate event of the Accepted checkbox is NOT the correct place for code that affects the value or enabled properties of the Accepted checkbox.

The code should probably be placed in the AfterUpdate event of all of the other checkboxes, so that any change in the other checkboxes will automatically change the Accepted checkbox as desired.
0
 
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAuthor Commented:
it did not work,

to make my question more clear ,i want to have it if any or all of the 5 following check boxes
Vbp
Vbv
Lhi
Lwt
Emr
are TRUE
Then
the check box  Acceptd  shall be TRUE
Else
Acceptd shall be FALSE
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
You should use the after update event of each of the following check boxes  Vbp, Vbv,  Lhi,  Lwt,  Emr

run this

Me.chkaccepted.enabled = (Me.Vbp or Me.Vbv or Me.Lhi or Me.Let or Me.Emr)   

Open in new window




and the form's on current event
 
If not Me.NewRecord then 
    Me.chkaccepted.enabled = (Me.Vbp or me.Vbv or Me.Lhi or Me.Let or Me.Emr) 
End IF

Open in new window


Also set the default value for the 5 check boxes to False.
0
 
mbizupCommented:
--->>> it did not work,

That doesn't really help.  Did you get an error message (which number/description)?  Incorrect results?  Etc?

Post the code that you tried.

This will *definitely* set the value of the check box to TRUE if any or all of the other checkboxes are checked and False if None are checked, assuming you have the right names:

 Me.Acceptd = Me.Vbp + me.Vbv + Me.Lhi + Me.Emr + Me.Lhw

Open in new window


As I mentioned earlier, the code needs to go in the After Update events of all of the checkboxes that appear on the right of the = sign to set the value of Acceptd when the user changes the value of any of the other checkboxes (not in the Before Update event, as you originally had it).

Also as Boyd Trimmell mentioned, the code should be added to the form's Current Event to set the value of Acceptd as the user navigates between records.
0
 
Dr.Abdulwahab Al-anesiProjects Information Technology ManagerAuthor Commented:
I've requested that this question be deleted for the following reason:

I trying to shift to share point
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.