How to make the controls locked on a form (immediatly)?

alex

Registered User.
Local time
Yesterday, 23:16
Joined
Apr 14, 2009
Messages
13
Hi,

I have a form that users fill on a tablet PC, and the content is transferred overnight on a server if they have checked the "completed" checkbox on the form.

I don't want them to be able to modify the content once they have checked the checkbox (but it's ok if they uncheck it and then modify the content..).

At first, I've tried to do Me.AllowEdits = False when the checkbox state changes to true, but the problem is, the user is then unable to uncheck the "completed" check-box because allow edits is set to false.

I've found on a forum a good workaround, lock all controls (except the check-box):

Code:
Public Function LockControls(lockState As Boolean)
    Dim oControl As Object
    
    For Each oControl In Me.Controls
         'Loop through the controls and set the value of the locked property
         Me.Controls(oControl.Name).Locked = lockState
    Next
    
    Me.CompleteCheck.Locked = False
That works well, but I have to go back to a previous record and then back to the current record to have the locked state applied to the controls. I've tried to add in the AfterUpdate event of the checkbox " If Me.Dirty Then Me.Dirty = False", but that doesn't work. I've also tried (in the same event) to add Me.Requery, but that brings the form back to the first record...

Any idea will be appreciated!
Thanks!
 
I would personally use the afterupdate event on the checkbox to determine if everything else should be locked or not.

If me.checkbox = 0 then
Unlock everything
Else
Lock everything except checkbox
End if

However if that code you have works perfectly except the Me.requery problem, this is how I got around that in the past. Use a variable to store the primary key

'Used to bring form back to the current record the user is viewing after requery
bookmark = PrimaryKeyValue

'Reset the form
Me.Requery
Me.Recordset.FindFirst "[PrimaryKeyValue] = " & bookmark
 
The "Me.Requery and Me.Recordset.FindFirst" is a nice workaround to my problem. I was hoping Ms Access would provide something cleaner to that particular situation, but if it works, why change it?! ;)

Thanks for your help
 

Users who are viewing this thread

Back
Top Bottom