Lock Fields With Change in Status (1 Viewer)

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
Hello everyone,


I appreciate all the help that I received on here.


I have a form AFRs that has a field 'Status'. Is there a way to have the fields locked when the value is changed from "Open" to "Closed" right away.



As it is now I have to leave that record and come back to it for the "Closed" to take affect.


Thank you very much,
Bill
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:12
Joined
Aug 30, 2003
Messages
36,131
Can't open the sample right now, but likely you need the same code in the after update event of the status field as you have in the current event (or a function called by both).
 

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
Okay thanks pbaldy.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:12
Joined
Aug 30, 2003
Messages
36,131
No problem. I'm on a computer now and looked at the db, and that should work for you.
 

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
I have this code in place provided by dbguy:


Code:
Private Sub Form_Current()
'thedbguy@gmail.com
'6/15/2019

If Not Me.NewRecord Then
    Me.AllowEdits = Me.cmbStatus <> "Closed"
    Me.AFRsParts1.Form.AllowEdits = Me.cmbStatus <> "Closed"
    Me.cmdUnlock.Visible = Me.cmbStatus = "Closed"
Else
    Me.cmdUnlock.Visible = False
End If

End Sub


Do I call this in the After Update for the 'Status' field? If so how?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:12
Joined
Aug 30, 2003
Messages
36,131
Personally I'd make it a form-level function and call it from both places. You can change Private to Public and call it from the after update event with:

Form_Current
 

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
Well what I tried didn't work:


Code:
Private Sub cmbStatus_AfterUpdate()
If Not Me.NewRecord Then
    Me.AllowEdits = Me.cmbStatus <> "Closed"
    Me.AFRsParts1.Form.AllowEdits = Me.cmbStatus <> "Closed"
    Me.cmdUnlock.Visible = Me.cmbStatus = "Closed"
Else
    Me.cmdUnlock.Visible = False
End If
End Sub
 

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
What am I doing wrong? What do you mean in both places. Sorry I am trying.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:12
Joined
Aug 30, 2003
Messages
36,131
Should work, my computer is acting up and I can't look at the sample right now. Hopefully somebody else can take a look.
 

missinglinq

AWF VIP
Local time
Today, 08:12
Joined
Jun 20, 2003
Messages
6,423
I can't open your db, I only run v2007, but in v2007 testing shows that in order for the Record to become Locked immediately after 'Closed' is selected, you'd need to Save to Record immediately after changing AllowEdits :

Code:
Me.AllowEdits = Me.cmbStatus <> "Closed"
If Me.Dirty Then Me.Dirty = False
But this scenario begs the question....WHY?

If the user accidentally selects 'Closed' from the Combobox (easy enough to do) when first entering data, how are they to correct the mistake?

Linq ;0)>
 

billgyrotech

Banned
Local time
Today, 07:12
Joined
Apr 18, 2013
Messages
258
I have the Status field in the header section so the user will not likely mess with it. If they do I have a button to unlock with a password.


I wish you could see the AFR form in question. I am learning but struggling with these codes and when to use for each scenario.


I do appreciate the help missinglinq
 

Users who are viewing this thread

Top Bottom