Access Form Multiple Checkbox's auto-populate the 3rd based off the 1st and 2nd Checkbox

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
I have 3 Checkboxes on my form and I'm trying to make the third checkbox automatically populate if the first 2 are checked, see below...Any suggestions on how this can be completed? For the Third checkbox Field C1 on my Form, I need it to auto-populate with True or Yes or -1 based off the 1st 2 being checked and if one of the 1st 2 is not then leave it blank...

Does this need to be in the Control Source, Default Value, or an expression built into the query for the form in order to get Field C1 to populate to -1?

IIf([A1]="Yes" And [B1]="Yes",[C1]=-1,"")
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Me.MoveDate = Date

Access VBA automatically dropped the () for date now Date()???
It doesn't require it.
Try it, and you'll see it returns the correct value.

Between Excel, Access, and VBA, I can never keep straight where it requries () and where it does not. However, it is smart enough to figure it out, and will help guide you along.
Don't be shy about trying some of these things out for yourself and see what happens. That is one of the best ways of learning (trial and error!).
 
Upvote 0
VBA Code:
If Me.Moved.Value = -1 And Me.Paid.Value = -1 Then
        Me.Completed.Value = -1
That will only work once. As soon as the 3rd checkbox becomes checked because 1 and 2 are checked it will stay that way. The reason is, that when 1 or 2 is unchecked the If block won't execute and there's no code to reverse it. Better to use something like
VBA Code:
Me.Check3 = Me.Check1 And Me.Check2
in the AfterUpdate events for 1 and 2. You don't need .Value
So the value of check3 is either True and True (equals true) or True and False (equals false) or False and True (equals false). However, I don't use macros so I can't say if macros cause checkbox AfterUpdate events to run.
 
Upvote 0
VBA Code:
If Me.Moved.Value = -1 And Me.Paid.Value = -1 Then
        Me.Completed.Value = -1
That will only work once. As soon as the 3rd checkbox becomes checked because 1 and 2 are checked it will stay that way. The reason is, that when 1 or 2 is unchecked the If block won't execute and there's no code to reverse it. Better to use something like
VBA Code:
Me.Check3 = Me.Check1 And Me.Check2
in the AfterUpdate events for 1 and 2. You don't need .Value
So the value of check3 is either True and True (equals true) or True and False (equals false) or False and True (equals false). However, I don't use macros so I can't say if macros cause checkbox AfterUpdate events to run.
Good point, I hadn't thought of that.
It looks like that is where CountTepes was probably going with this too.
 
Upvote 0
So, do I place these in On Click or After Update and If Moved is clicked and later then Paid is clicked, it should automatically place a check mark in Completed. So for the 1st checkbox which is Moved, do I need this to be On Click or After Update? Thanks for all you guys assistance in making this a smooth flow by the way...Still learning VB but it's coming to me with people like you all assisting...
 
Upvote 0
Maybe try putting it both in OnClick and AfterUpdate.
Sometimes, if I am unsure which one is calling the code, I will add a MsgBox to my code like this:
VBA Code:
MsgBox "OnClick code being called"
while debugging.

It doesn't hurt to have it in too many places.
 
Upvote 0
Put what I suggested in the AfterUpdate event for both checks. Use the names of your controls, not mine. The one being altered by code should not have this code. Click event is not appropriate for this.
 
Upvote 0
You could always put in breakpoints in the code
F9 where your cursor is, then step through
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,111
Members
452,544
Latest member
aush

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top