Problem with static variables

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
 
D

Dickie Black

Forgot to add:

Command button code:

Private Sub LockButton_Click()

'toggle form record locks
Locked = Not Locked

Call LockFields

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top