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

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:51
Joined
Feb 28, 2001
Messages
26,999
Something like what you posted, but also look at what Arnelgp proposed in post #9 of this thread. For those things that use the same criteria, compute the common value first in a simple variable local to the routine and then assign that value to all the cases that use the same rules. Makes for a LOT less code and is easy to understand when reading.

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

There is no way for me to know that, but perhaps I can give you a guideline. Normally, the individual "click" events seem to trigger some kind of visibility change for you. So you need to lay out on paper some kind of rules that are imposed by each such click event. (This is a bit tedious but can't be helped.) Now gather like rules together based on which click does which job. For those events that use the same exact rules each time regardless of which of your controls is clicked, they can call a common routine that has the same effect. If there are differences in effect, then you need routines that recognize the differences. Your routines APPEAR (from our end of the telescope) to be duplicating effort in a way that makes it hard to know which controls will and which controls won't become visible. (I.e. as you point out, visibility becomes a problem of inconsistency.) There is NO substitute for this... step away from the code and lay out some kind of "map" that tells you what each click is supposed to do if taken in isolation. Group all that are alike. Apply what arnelgp and I have told you about code structure to minimize typing AND clarity.

You would use individual click events based on your users clicking individual controls.

When you use the LOAD event for the form, you would set the visibility to whatever is its default position. One routine that sets visibility would do the job. But... if this is a bound form, you don't need a LOAD event because you are about to execute a CURRENT event that is a far better. It will have values in all of the bound controls and you can run the "global" changes ONCE (per CURRENT event) there. Then let the individuals do their jobs. That comes down to ONE (and only one) event routine to address ALL of the controls, plus your individual click event routines which might affect fewer controls. There is this philosophy that many of use espouse - KISS. I'll keep it clean... Keep It Simple, Silly.
 

Chief

Registered User.
Local time
Today, 08:51
Joined
Feb 22, 2012
Messages
156
Something like what you posted, but also look at what Arnelgp proposed in post #9 of this thread. For those things that use the same criteria, compute the common value first in a simple variable local to the routine and then assign that value to all the cases that use the same rules. Makes for a LOT less code and is easy to understand when reading.



There is no way for me to know that, but perhaps I can give you a guideline. Normally, the individual "click" events seem to trigger some kind of visibility change for you. So you need to lay out on paper some kind of rules that are imposed by each such click event. (This is a bit tedious but can't be helped.) Now gather like rules together based on which click does which job. For those events that use the same exact rules each time regardless of which of your controls is clicked, they can call a common routine that has the same effect. If there are differences in effect, then you need routines that recognize the differences. Your routines APPEAR (from our end of the telescope) to be duplicating effort in a way that makes it hard to know which controls will and which controls won't become visible. (I.e. as you point out, visibility becomes a problem of inconsistency.) There is NO substitute for this... step away from the code and lay out some kind of "map" that tells you what each click is supposed to do if taken in isolation. Group all that are alike. Apply what arnelgp and I have told you about code structure to minimize typing AND clarity.

You would use individual click events based on your users clicking individual controls.

When you use the LOAD event for the form, you would set the visibility to whatever is its default position. One routine that sets visibility would do the job. But... if this is a bound form, you don't need a LOAD event because you are about to execute a CURRENT event that is a far better. It will have values in all of the bound controls and you can run the "global" changes ONCE (per CURRENT event) there. Then let the individuals do their jobs. That comes down to ONE (and only one) event routine to address ALL of the controls, plus your individual click event routines which might affect fewer controls. There is this philosophy that many of use espouse - KISS. I'll keep it clean... Keep It Simple, Silly.

Ok, Thank you so much.. :D

Ill get my head into this and report back. (y)
 

Chief

Registered User.
Local time
Today, 08:51
Joined
Feb 22, 2012
Messages
156
So Good!

You guys have made me very happy and taught me a lot.
Thank you so much.. :D

This is what I did, couple of examples:

Code:
'------------------------------------------------------------
' Options Visible if true
'------------------------------------------------------------
    Private Sub ChkLaminateBtops_Click()
        Call BTop_Visible ' Group common fields - Bench tops
    End Sub

    Private Sub ChkCarcassEdge_Click()
            Call ComMachShop ' Group common fields - Machine Shop
            Me.ChkCC_Edge.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.LblCC_Edge.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.TxtCarcassEdge.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.LblCC_EdgeLm.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.TxtCC_EdgeLm.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.LblCarcassEdge_Due.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.TxtCarcassEdge_Due.Visible = CBool(Nz(Me.ChkCarcassEdge, 0))
    End Sub


    Private Sub ChkBIDs_Click()
            Me.LblBID_Due.Visible = CBool(Nz(Me.ChkBIDs, 0))
            Me.TxtBID_Due.Visible = CBool(Nz(Me.ChkBIDs, 0))
            Me.ChkBID_Rec.Visible = CBool(Nz(Me.ChkBIDs, 0))
            Me.LblBID_Rec.Visible = CBool(Nz(Me.ChkBIDs, 0))
            Me.TxtBID_Rec.Visible = CBool(Nz(Me.ChkBIDs, 0))
    End Sub



'------------------------------------------------------------
' Options Visible - Group common fields
'------------------------------------------------------------
    ' Benchtops
    Private Sub BTop_Visible()
        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 Sub

But couldn't work this one out, its looking at a combobox for a "Value" so I just did an else

Code:
    Private Sub CboDeliverPickUp_Click()
        If Me.CboDeliverPickUp = "Delivery" Then
            Me.CboDrivers.Visible = True
            Me.LblDrivers.Visible = True
            Me.LblTransport.Visible = True
            Me.CboTransport.Visible = True
            Me.LblDelMins.Visible = True
            Me.TxtDelMins.Visible = True
            Me.TxtDelHrs.Visible = True
            Me.LblDelHrs.Visible = True
        Else
            Me.CboDrivers.Visible = False
            Me.LblDrivers.Visible = False
            Me.LblTransport.Visible = False
            Me.CboTransport.Visible = False
            Me.LblDelMins.Visible = False
            Me.TxtDelMins.Visible = False
            Me.TxtDelHrs.Visible = False
            Me.LblDelHrs.Visible = False
        End If
    End Sub

Thank you again....
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,169
Code:
    Private Sub CboDeliverPickUp_Click()
        Dim tfVisible As Boolean
        tfVisible = (Me.CboDeliverPickUp & "" = "Delivery")
        Me.CboDrivers.Visible = tfVisible
        Me.LblDrivers.Visible = tfVisible
        Me.LblTransport.Visible = tfVisible
        Me.CboTransport.Visible = tfVisible
        Me.LblDelMins.Visible = tfVisible
        Me.TxtDelMins.Visible = tfVisible
        Me.TxtDelHrs.Visible = tfVisible
        Me.LblDelHrs.Visible = tfVisible
    End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,169
Code:
'------------------------------------------------------------
' Options Visible if true
'------------------------------------------------------------
    Private Sub ChkLaminateBtops_Click()
        Call BTop_Visible ' Group common fields - Bench tops
    End Sub

    Private Sub ChkCarcassEdge_Click()
            Dim tfVisible As Boolean
            Call ComMachShop ' Group common fields - Machine Shop
            tfVisible = CBool(Nz(Me.ChkCarcassEdge, 0))
            Me.ChkCC_Edge.Visible = tfVisible
            Me.LblCC_Edge.Visible = tfVisible
            Me.TxtCarcassEdge.Visible = tfVisible
            Me.LblCC_EdgeLm.Visible = tfVisible
            Me.TxtCC_EdgeLm.Visible = tfVisible
            Me.LblCarcassEdge_Due.Visible = tfVisible
            Me.TxtCarcassEdge_Due.Visible = tfVisible
    End Sub


    Private Sub ChkBIDs_Click()
            Dim tfVisible As Boolean
            tfVisible = CBool(Nz(Me.ChkBIDs, 0))
            Me.LblBID_Due.Visible =tfVisible
            Me.TxtBID_Due.Visible = tfVisible
            Me.ChkBID_Rec.Visible = tfVisible
            Me.LblBID_Rec.Visible = tfVisible
            Me.TxtBID_Rec.Visible = tfVisible
    End Sub



'------------------------------------------------------------
' Options Visible - Group common fields
'------------------------------------------------------------
    ' Benchtops
    Private Sub BTop_Visible()
        Dim tfVisible As Boolean
        tfVisible = CBool(Nz(Me.ChkLaminateBtops, 0)) Or CBool(Nz(Me.ChkSolidSurfaceTops, 0)) Or CBool(Nz(Me.ChkBtopOther, 0))
        Me.TxtBTop_Due.Visible = tfVisible
        Me.LblBTop_Due.Visible = tfVisible
        Me.ChkBTop_Rec.Visible = tfVisible
        Me.LblBTop_Rec.Visible = tfVisible
        Me.TxtBTop_Rec.Visible = tfVisible
    End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:51
Joined
Feb 28, 2001
Messages
26,999
Looks like arnelgp and I are tag-teaming you. I'll step away since arnelgp provided some routines for you to study and consider. His code is usually worth a look. If you later need further clarification, just ask in this thread.
 
Last edited:

Chief

Registered User.
Local time
Today, 08:51
Joined
Feb 22, 2012
Messages
156
Looks like arnelgp and I are tag-teaming you. I'll step away since arnelgp provided some routines for you to study and consider. His code is usually work a look. If you later need further clarification, just ask in this thread.
Cheers mate :)
 

Chief

Registered User.
Local time
Today, 08:51
Joined
Feb 22, 2012
Messages
156
thanks heaps guys...

Quick one,
Why would i still be getting asked to complete this date when I have a date in there?

1638147895674.png


Code:
Private Sub LblSetOut_Complete_Click()
    Dim txtmessage As String
    txtmessage = ""
    ' Check Orders Due Dates
        If ChkBoardOrder = True And Len(Nz(Me.TxtBoard_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Board Order." & vbCrLf & txtmessage)
            Me.TxtBoard_Due.BackColor = vbRed
            Me.TxtBoard_Due.ForeColor = vbWhite
            Me.TxtBoard_Due.SetFocus
        ElseIf ChkEdgeOrder = True And Len(Nz(Me.TxtEdging_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Edging Order." & vbCrLf & txtmessage)
            Me.TxtEdging_Due.BackColor = vbRed
            Me.TxtEdging_Due.ForeColor = vbWhite
            Me.TxtEdging_Due.SetFocus
        ElseIf ChkHW_Order = True And Len(Nz(Me.TxtHardware_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Hardware Order." & vbCrLf & txtmessage)
            Me.TxtHardware_Due.BackColor = vbRed
            Me.TxtHardware_Due.ForeColor = vbWhite
            Me.TxtHardware_Due.SetFocus
        ElseIf ChkBIDs = True And Len(Nz(Me.TxtBID_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Bought In Doors Order." & vbCrLf & txtmessage)
            Me.TxtBID_Due.BackColor = vbRed
            Me.TxtBID_Due.ForeColor = vbWhite
            Me.TxtBID_Due.SetFocus
        ElseIf ChkLaminateBtops = True Or ChkSolidSurfaceTops = True Or ChkBtopOther = True And (Nz(Me.TxtBTop_Due, 0)) Then ' Len(Nz(Me.TxtBTop_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Bench Top Order." & vbCrLf & txtmessage)
            Me.TxtBTop_Due.BackColor = vbRed
            Me.TxtBTop_Due.ForeColor = vbWhite
            Me.TxtBTop_Due.SetFocus

There are further elseif..
I tried len and nz and just nz. (Its the last one that is failing)

thanks

Update: It must be to do with the or statements??
 
Last edited:

Chief

Registered User.
Local time
Today, 08:51
Joined
Feb 22, 2012
Messages
156
thanks heaps guys...

Quick one,
Why would i still be getting asked to complete this date when I have a date in there?

View attachment 96439

Code:
Private Sub LblSetOut_Complete_Click()
    Dim txtmessage As String
    txtmessage = ""
    ' Check Orders Due Dates
        If ChkBoardOrder = True And Len(Nz(Me.TxtBoard_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Board Order." & vbCrLf & txtmessage)
            Me.TxtBoard_Due.BackColor = vbRed
            Me.TxtBoard_Due.ForeColor = vbWhite
            Me.TxtBoard_Due.SetFocus
        ElseIf ChkEdgeOrder = True And Len(Nz(Me.TxtEdging_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Edging Order." & vbCrLf & txtmessage)
            Me.TxtEdging_Due.BackColor = vbRed
            Me.TxtEdging_Due.ForeColor = vbWhite
            Me.TxtEdging_Due.SetFocus
        ElseIf ChkHW_Order = True And Len(Nz(Me.TxtHardware_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Hardware Order." & vbCrLf & txtmessage)
            Me.TxtHardware_Due.BackColor = vbRed
            Me.TxtHardware_Due.ForeColor = vbWhite
            Me.TxtHardware_Due.SetFocus
        ElseIf ChkBIDs = True And Len(Nz(Me.TxtBID_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Bought In Doors Order." & vbCrLf & txtmessage)
            Me.TxtBID_Due.BackColor = vbRed
            Me.TxtBID_Due.ForeColor = vbWhite
            Me.TxtBID_Due.SetFocus
        ElseIf ChkLaminateBtops = True Or ChkSolidSurfaceTops = True Or ChkBtopOther = True And (Nz(Me.TxtBTop_Due, 0)) Then ' Len(Nz(Me.TxtBTop_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Bench Top Order." & vbCrLf & txtmessage)
            Me.TxtBTop_Due.BackColor = vbRed
            Me.TxtBTop_Due.ForeColor = vbWhite
            Me.TxtBTop_Due.SetFocus

There are further elseif..
I tried len and nz and just nz. (Its the last one that is failing)

thanks

Update: It must be to do with the or statements??
I did this:

Code:
        ElseIf ChkLaminateBtops = True And Len(Nz(Me.TxtBTop_Due)) = 0 Or ChkSolidSurfaceTops = True And Len(Nz(Me.TxtBTop_Due)) = 0 Or ChkBtopOther = True And Len(Nz(Me.TxtBTop_Due)) = 0 Then
            txtmessage = MsgBox("Enter Due date for Bench Top Order." & vbCrLf & txtmessage)
            Me.TxtBTop_Due.BackColor = vbRed
            Me.TxtBTop_Due.ForeColor = vbWhite
            Me.TxtBTop_Due.SetFocus
        ElseIf ChkGlazing = True And Len(Nz(Me.TxtGlass_Due)) = 0 Then

Think its working now.

thanks guys.
really appreciate the help and quick responses.

(y) (y):)
 

Users who are viewing this thread

Top Bottom