Question

I have created a control in the form of a checkbox which upon activating it, certain controls are made visible.. Upon deactivating it, the controls are made invisible. My issue is upon the form load. The first time selecting the checkbox (on mousedown event), nothing happens forcing the user to unselect it, and then reselect it.. On the reselect, it works fine.. I imagine that I need to do some type of refresh somewhere but i cant figure out how.. would someone be able to give me a hand? Below is my code.. Thanks

Private Sub cmdAccounting_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.cmdAccounting = 0 Then
    cost.Visible = True
    Etichetta35.Visible = True
    Etichetta37.Visible = True
    Etichetta43.Visible = True
    qty.Visible = True
    tot.Visible = True
    lineaAccounting1.Visible = True
    lineaAccounting2.Visible = True
    Me.FileSaved.Visible = False
    Me.lblFileSaved.Visible = False
Else
    cost.Visible = False
    Etichetta35.Visible = False
    Etichetta37.Visible = False
    Etichetta43.Visible = False
    qty.Visible = False
    tot.Visible = False
    lineaAccounting1.Visible = False
    lineaAccounting2.Visible = False
    Me.FileSaved.Visible = True
    Me.lblFileSaved.Visible = True

End If
Me.Form.Refresh
End Sub
Was it helpful?

Solution

I'd suggest that you keep move to code to its own Sub, something like Sub UpdateControls(). You can then call that Sub in two places: Form_Current and the _AfterUpdate event of any control that should change the state. Remove the Me.Form.Refresh line. Form_current fires when the first record is displayed and again anytime the user navigates. AfterUpdate will fire when the checkbox is changed within a record.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top