Problem with static variables

  • Thread starter Thread starter Dickie Black
  • Start date Start date
D

Dickie Black

Hi,

I've got a boolean static variable defined in a forms OnLoad event and set
to True. I then call a private sub which looks at the value for this
variable and does things depending on its value. A command button sets the
value to its opposite on click. Unfortunately it doesn't seem to work...
It's basically supposed to lock some text boxes to prevent accidental
alteration of data and is quite simple, code-wise.

Code example:

Private Sub Form_Load()

Static Locked As Boolean

Locked = True

Call LockFields

End Sub

Private Sub LockFields()

'Alter caption to reflect edit status
If Locked = True Then

Me.LockButton.Caption = "Unlock"
Me.InfoLabel.Caption = "Records locked: click the button to edit
details"
'+ code to lock/unlock various texboxes

Else

Me.LockButton.Caption = "Lock"
Me.InfoLabel.Caption = "Records unlocked: You may edit details"
'+ code to lock/unlock various texboxes

End If

End Sub

Should the call sub be public? Or should it not be a sub at all? Anyone
got any ideas?

Thanks,

Dickie
 
Forgot to add:

Command button code:

Private Sub LockButton_Click()

'toggle form record locks
Locked = Not Locked

Call LockFields

End Sub
 
Back
Top