On click event and call click event not functioning. (1 Viewer)

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
Hello,
I have a form with an on click event that makes fields visible when checked.
I am then calling the click event when the form loads, opens and current.

The on click is working, however when i reopen the form the status of the job doesnt hold the changes even when the checkbox is true.
I have a few of these, all seem to be working except this one. Not sure why if anyone can help?

Code:
    Private Sub ChkAssembled_Click()
        If Me.ChkAssembled = True Then
            Me.LblProdTick.Visible = True
            Me.CboAssemblers.Visible = True
            Me.LblAssemblers.Visible = True
            Me.LblActualMins.Visible = True
            Me.TxtActualMins.Visible = True
            Me.TxtActualHours.Visible = True
            Me.LblActualHours.Visible = True
            Me.LblAssComplete.Visible = True
            Me.LblAssComp.Visible = True
            Me.LblAssDate.Visible = True
            Me.TxtAssComplete.Visible = True
            Me.TxtAssemblyDue.Visible = True
            Me.LblAssemblyDue.Visible = True
        Else
            Me.LblProdTick.Visible = False
            Me.CboAssemblers.Visible = False
            Me.LblAssemblers.Visible = False
            Me.LblActualMins.Visible = False
            Me.TxtActualMins.Visible = False
            Me.TxtActualHours.Visible = False
            Me.LblActualHours.Visible = False
            Me.LblAssComplete.Visible = False
            Me.LblAssComp.Visible = False
            Me.LblAssDate.Visible = False
            Me.TxtAssComplete.Visible = False
            Me.TxtAssemblyDue.Visible = False
            Me.LblAssemblyDue.Visible = False
        End If
    End Sub

Code:
Private Sub Form_Open(Cancel As Integer)
    Call CboJobTypeID_Click
    Call ChkLaminateBtops_Click
    Call ChkSolidSurfaceTops_Click
    Call ChkBtopOther_Click
    Call ChkSubstrates_Click
    Call ChkTemplates_Click
    Call ChkCarcassCut_Click
    Call ChkCarcassEdge_Click
    Call ChkPFBCut_Click
    Call ChkPFBEdge_Click
    Call ChkWhiteSatCut_Click
    Call ChkTwoPakPaint_Click
    Call ChkHingeDrill_Click
    Call ChkBIDs_Click
    Call ChkAssembled_Click
    Call ChkFingerP_Click
    Call ChkPickHW_Click
    Call ChkGlazing_Click
    Call ChkMetalWork_Click
    Call ChkBoardOrder_Click
    Call ChkEdgeOrder_Click
    Call ChkHW_Order_Click
    Call CboDeliverPickUp_Click
    Call CboSupplyInstall_Click
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:52
Joined
Oct 29, 2018
Messages
21,358
Hi. Only thing I could think of at this point: Have you stepped through the code as it executes?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:52
Joined
May 7, 2009
Messages
19,169
move your code to the Load Event of the form.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:52
Joined
Feb 28, 2001
Messages
26,999
Just to clarify AND AGREE with Arnel.... The form hasn't been loaded at the time of the Open Event so no controls are available. Also, in the Load event, the controls might exist but they are not yet current to the underlying recordset, so they are probably null. Which in turn probably means that Me.ChkAssembled is neither true nor false - yet.

Looking at the code you showed us, if your symptom is "controls aren't visible" then look to the value of Me.ChkAssembled because if it is not TRUE then your list of affected controls WILL be invisible.
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
Just to clarify AND AGREE with Arnel.... The form hasn't been loaded at the time of the Open Event so no controls are available. Also, in the Load event, the controls might exist but they are not yet current to the underlying recordset, so they are probably null. Which in turn probably means that Me.ChkAssembled is neither true nor false - yet.

Looking at the code you showed us, if your symptom is "controls aren't visible" then look to the value of Me.ChkAssembled because if it is not TRUE then your list of affected controls WILL be invisible.
Thank you,

The table value is set to true.
However when I step thru the code the highlighted ChkAssembled states -1

is that true?

thank you
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
G'day Mate,
Yes I have the Call there too.
I'm finding a couple of these are not working now but some are.
Does it matter that some fields are in a page on the form?
Do I need to specify the form every time? or me. is adequate.

Actually some records work and some don't as well.
Its really random now.. :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:52
Joined
May 7, 2009
Messages
19,169
you should also "call" the ChkAssembled_Click() on the Current Event of the form.
i an only simplifying your code:
Code:
    Private Sub ChkAssembled_Click()
        dim bolVisible As Boolean
        bolVisible = Nz(Me.ChkAssembled, 0)
        Me.LblProdTick.Visible = bolVisible
        Me.CboAssemblers.Visible = bolVisible
        Me.LblAssemblers.Visible = bolVisible
        Me.LblActualMins.Visible = bolVisible
        Me.TxtActualMins.Visible = bolVisible
        Me.TxtActualHours.Visible = bolVisible
        Me.LblActualHours.Visible = bolVisible
        Me.LblAssComplete.Visible =  bolVisible
        Me.LblAssComp.Visible = bolVisible
        Me.LblAssDate.Visible = bolVisible
        Me.TxtAssComplete.Visible = bolVisible
        Me.TxtAssemblyDue.Visible = bolVisible
        Me.LblAssemblyDue.Visible = bolVisible
    End Sub
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
you should also "call" the ChkAssembled_Click() on the Current Event of the form.
i an only simplifying your code:
Code:
    Private Sub ChkAssembled_Click()
        dim bolVisible As Boolean
        bolVisible = Nz(Me.ChkAssembled, 0)
        Me.LblProdTick.Visible = bolVisible
        Me.CboAssemblers.Visible = bolVisible
        Me.LblAssemblers.Visible = bolVisible
        Me.LblActualMins.Visible = bolVisible
        Me.TxtActualMins.Visible = bolVisible
        Me.TxtActualHours.Visible = bolVisible
        Me.LblActualHours.Visible = bolVisible
        Me.LblAssComplete.Visible =  bolVisible
        Me.LblAssComp.Visible = bolVisible
        Me.LblAssDate.Visible = bolVisible
        Me.TxtAssComplete.Visible = bolVisible
        Me.TxtAssemblyDue.Visible = bolVisible
        Me.LblAssemblyDue.Visible = bolVisible
    End Sub
Thank you
I have the call values in On Current and in On Load.

Still have issues.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:52
Joined
May 7, 2009
Messages
19,169
is the checkbox "ChkAssembled" Bound to a field?
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
is the checkbox "ChkAssembled" Bound to a field?
Yes
1637811266349.png


1637811307773.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:52
Joined
May 7, 2009
Messages
19,169
where is the "control" located, main form?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:52
Joined
Feb 28, 2001
Messages
26,999
Does it matter that some fields are in a page on the form?

No. The "tab pages" on a form are all part of the form. The page where a control is located does not have to be "on top" for the control to be visible TO THE CODE even though it will not be visible to the eye. They are all part of "Me." and as such, they are all visible to the routines of the class module.

I noted that you have a sequence of calls to various click routines. Is it possible that some of those "implied clicks" overlap to cause you the problem of not seeing some of the controls that you wanted to make visible?
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
No. The "tab pages" on a form are all part of the form. The page where a control is located does not have to be "on top" for the control to be visible TO THE CODE even though it will not be visible to the eye. They are all part of "Me." and as such, they are all visible to the routines of the class module.

I noted that you have a sequence of calls to various click routines. Is it possible that some of those "implied clicks" overlap to cause you the problem of not seeing some of the controls that you wanted to make visible?
hmmm

Ill go thru them..

thanks
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
No. The "tab pages" on a form are all part of the form. The page where a control is located does not have to be "on top" for the control to be visible TO THE CODE even though it will not be visible to the eye. They are all part of "Me." and as such, they are all visible to the routines of the class module.

I noted that you have a sequence of calls to various click routines. Is it possible that some of those "implied clicks" overlap to cause you the problem of not seeing some of the controls that you wanted to make visible?

I think you are onto something here.
If I comment out all code for the visible on and off,
only have one event on, so to be speak, the function works as it should.

I know my code is horrible and repetitive. Is this the issue?
How can I code this correctly to make it work?
Or, what do I need to look for that causes this issue?

thank you
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:52
Joined
Feb 28, 2001
Messages
26,999
What you should look for is that some of those other event routines that you are calling touch the same controls as the one you showed us, but they have different "rules" about what to show and when. Just remember, in linear code execution, the last thing called is what you see.

If that is the case, then you have a case of "too many cooks spoil the broth" going on. I don't know how many controls you have running, but what I would do is based on this guess - you are trying to initialize the form by calling all of those event routines. Instead, make a single routine that sets everything ONCE. Rather than calling "dueling event routines" have a single utility routine that sets everything based on tests.

If you have a control whose visibility depends on a single checkbox, do this:

Code:
Me.OneTrickPony.Visible = CBool(Nz( Me.ckbOneTrick, 0 ) )

If you have a control whose visibility depends on two checkboxes BOTH being set, do this

Code:
Me.TwoTrickPony.Visible = CBool(Nz( Me.ckbFirstTrick, 0 )) AND CBool(Nz( Me.ckbSecondTrick, 0 ))

If that is where EITHER checkbox is set, use OR instead of AND.

What you have NOW is a sequence of check-this-box-and-set, then check-another-box-then-set, ... down the line - but if you have multiple dependencies, particularly if it is a bound form, you process a LOT of controls. Not to mention that with all those calls, the "last event called" is the only one that works as expected. All others (in prior calls) might get overwritten. It's a "last man standing" free-for-all.

The other side of this is that if you have the "one routine does it all" style, it makes your Form_Load and Form_Current routines easier - and faster. But then, to finish this off, leave the individual (selective) event routines as-is, on the theory that you init'ed everything in the _Current routine, so everything else until the next _Current routine is just a "spot change" as opposed to a wholesale or overall change.
 

Minty

AWF VIP
Local time
Today, 18:52
Joined
Jul 26, 2013
Messages
10,355
I would add a tag value to those controls and loop around them to simplify the code even further.
I don't understand the reasoning behind calling all those click events on load?

What do they all do?
 

Chief

Registered User.
Local time
Today, 11:52
Joined
Feb 22, 2012
Messages
156
What you should look for is that some of those other event routines that you are calling touch the same controls as the one you showed us, but they have different "rules" about what to show and when. Just remember, in linear code execution, the last thing called is what you see.

If that is the case, then you have a case of "too many cooks spoil the broth" going on. I don't know how many controls you have running, but what I would do is based on this guess - you are trying to initialize the form by calling all of those event routines. Instead, make a single routine that sets everything ONCE. Rather than calling "dueling event routines" have a single utility routine that sets everything based on tests.

If you have a control whose visibility depends on a single checkbox, do this:

Code:
Me.OneTrickPony.Visible = CBool(Nz( Me.ckbOneTrick, 0 ) )

If you have a control whose visibility depends on two checkboxes BOTH being set, do this

Code:
Me.TwoTrickPony.Visible = CBool(Nz( Me.ckbFirstTrick, 0 )) AND CBool(Nz( Me.ckbSecondTrick, 0 ))

If that is where EITHER checkbox is set, use OR instead of AND.

What you have NOW is a sequence of check-this-box-and-set, then check-another-box-then-set, ... down the line - but if you have multiple dependencies, particularly if it is a bound form, you process a LOT of controls. Not to mention that with all those calls, the "last event called" is the only one that works as expected. All others (in prior calls) might get overwritten. It's a "last man standing" free-for-all.

The other side of this is that if you have the "one routine does it all" style, it makes your Form_Load and Form_Current routines easier - and faster. But then, to finish this off, leave the individual (selective) event routines as-is, on the theory that you init'ed everything in the _Current routine, so everything else until the next _Current routine is just a "spot change" as opposed to a wholesale or overall change.
Ok, awesome, thank you.
I'll start re-doing all my code.

Do I do this for all of the on click events? then Call those events Load and Current?

Like this? (Do I still need the else to set to invisible?)

Code:
'------------------------------------------------------------
' Options Visible if true
'------------------------------------------------------------
    Private Sub ChkLaminateBtops_Click()
        If Me.ChkLaminateBtops = True Then
            Me.LblDispLogTick.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.LblInwards.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.LblReceive.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.TxtBTop_Due.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.LblBTop_Due.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.ChkBTop_Rec.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.LblBTop_Rec.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
            Me.TxtBTop_Rec.Visible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
        End If
    End Sub
 

Users who are viewing this thread

Top Bottom