Help with check box manipulation (1 Viewer)

slharman1

Member
Joined
Mar 8, 2021
Messages
483
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
 
Why have that code in the main forms current event and not the subforms?
in the subforms on current
chkIsComplete = (QtyAvail = 0)
 
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
 
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.”
 
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.
 
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.
 
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!
 
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?
 
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!
 
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...
 

Users who are viewing this thread

Back
Top Bottom