Help with check box manipulation (1 Viewer)

slharman1

Member
Local time
Today, 09:32
Joined
Mar 8, 2021
Messages
476
I have this code in the on current event of a main form
I want a checkbox on the subform to change the value to false if QtyAvail = 0
But it is not updating.

Code:
Private Sub Form_Current()

    If Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!QtyAvail = 0 Then
    Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!chkIsComplete = True
    Else
    Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!chkIsComplete = False
    End If
  
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,480
Try setting the focus to the subform first.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,545
Why have that code in the main forms current event and not the subforms?
in the subforms on current
chkIsComplete = (QtyAvail = 0)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Feb 19, 2013
Messages
16,622
change the value to false if QtyAvail = 0
Your code changes it to true if QtyAvail=0
Code:
If Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!QtyAvail = 0 Then
    Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!chkIsComplete = True
 

slharman1

Member
Local time
Today, 09:32
Joined
Mar 8, 2021
Messages
476
Your code changes it to true if QtyAvail=0
Code:
If Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!QtyAvail = 0 Then
    Me!frmOrderDetailsListToMarkForCompletionWthQty.Form!chkIsComplete = True
If QtyAvail =0 then the check box should be checked. If not it should be unchecked.
This is for a completion form, so if there are none available to be completed, then the checkbox is checked “Marked as Complete.”
 

slharman1

Member
Local time
Today, 09:32
Joined
Mar 8, 2021
Messages
476
I corrected some bad data and now there is no issue. I do t need the code. Still don’t k ow why it would not update the checkbox though. That’ll keep me up all night I am sure.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:32
Joined
Feb 19, 2002
Messages
43,314
So much wrong. Where to start.

If you need to correct bad data, you could do it with an update query rather than temporarily modifying code in a form.

Automatically running an update in the current event is scary at many levels. If you ever think you need to do this, at least add a button or some positive action. Just navigating to a record should never cause an update to happen - it might cause a log event if you want to track views of a record.

I can't tell if the subform shows multiple records or only one. The point here is that only ONE row of the subform can ever have focus at one time. So, updating a subform record from a different form will result in the update being made to whatever ACCESS thinks is the ONE, CURRENT record. Technically, in the current event of the parent form, the first visible row of the subform is the current record and that is the one that should be updated. Was that your intention? to update ONLY the FIRST row of the subform? If your intention was to update ALL child rows, then the code would never work.

It is poor practice to have the same data in two places the way you are with those two fields indicates that it is essentially the same information. If the flag of the main form is ALWAYS opposite the flag of the subform records, then the subform flag is redundant. If the subform rows might have different values, then how is the setting of the main form record determined?

To figure out why the code did not work correctly, place a stop on the if and step through the code.
 

slharman1

Member
Local time
Today, 09:32
Joined
Mar 8, 2021
Messages
476
So much wrong. Where to start.

If you need to correct bad data, you could do it with an update query rather than temporarily modifying code in a form.

Automatically running an update in the current event is scary at many levels. If you ever think you need to do this, at least add a button or some positive action. Just navigating to a record should never cause an update to happen - it might cause a log event if you want to track views of a record.

I can't tell if the subform shows multiple records or only one. The point here is that only ONE row of the subform can ever have focus at one time. So, updating a subform record from a different form will result in the update being made to whatever ACCESS thinks is the ONE, CURRENT record. Technically, in the current event of the parent form, the first visible row of the subform is the current record and that is the one that should be updated. Was that your intention? to update ONLY the FIRST row of the subform? If your intention was to update ALL child rows, then the code would never work.

It is poor practice to have the same data in two places the way you are with those two fields indicates that it is essentially the same information. If the flag of the main form is ALWAYS opposite the flag of the subform records, then the subform flag is redundant. If the subform rows might have different values, then how is the setting of the main form record determined?

To figure out why the code did not work correctly, place a stop on the if and step through the code.
Hi Pat, Thanks for chiming in! I hope you're doing well.
What I was trying to accomplish is a mute point. I fixed my data with an update query, I was attempting to be able for a user's mistake to be corrected with code. Instead I ended up writing the code to keep them from making the mistake.. Being that you know my DB makes a big difference in getting some assistance, I have recently added another table to allow entering a partial qty of completion so we can better track the throughput of the shop fabrication. We are able now to track our fabrication sales on a weekly basis now (in no small part, thanks to your help) we can actually track it for any time period we want.
Thanks again for all your assistance with our system!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:32
Joined
Feb 19, 2002
Messages
43,314
Hi Steve. You're welcome. I'm glad the app is working for you. You really did a great job with it. How did the move go?
 

slharman1

Member
Local time
Today, 09:32
Joined
Mar 8, 2021
Messages
476
Hi Steve. You're welcome. I'm glad the app is working for you. You really did a great job with it. How did the move go?
The move went as well as expected. We're all settled in finally. It's already too small though - our salesmen are real go getters. Wearing me out :)
The app is working great, thanks again for all your help!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,480
Hi. I need help with the following please.

When I type in a number in the StudentBookIssue_ID the code runs perfectly and the checkbox get checked.
When I set the field to an autonumber the number gets inserted but the code does not get execute. And my
IssuedLearner.Value stay false.


Private Sub StudentBookIssue_ID_AfterUpdate()
If (StudentBookIssue_ID.Value = True) And (IssuedLearner.Value = False) Then
IssuedLearner.Value = True
End If

Thanks
Probably should start your own thread...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,480
Ok. Not posted a lot . Not sure where to start a new thread. Thanks
Go to the appropriate Forum (Forms, for example) and then click on the "Post Thread" button.
 

Users who are viewing this thread

Top Bottom