Question Unlock Field after update, more than one set. (1 Viewer)

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Hi,

There have been plenty of threads on having a field unlock after another field has been updated. I have 5 sets of an option group and text box. I want the option group locked/disabled when the text box is empty. Maybe one might sufficient. Here is the code I'm using in both in AfterUpdate and OnCurrent:

If IsNull(Me.Text83) Or Me.Text83 = "" Then
Me.Frame188.Enabled = False
Me.Frame188.Locked = True
Else
Me.Frame188.Enabled = True
Me.Frame188.Locked = False
End If

My question is: How can do this for the other 4 sets? Do I have put this code in both places for each locking set or is their a shorter way?

Thanks so much!
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Any ideas? If I have to copy this code for each set than that's fine.
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
You could create a custom function -

Code:
Function SetLockEnabled(frm As Form, strOptionGroup As String, strTextBox As String)
    If Len(frm.Controls(strTextBox) & "") = 0 Then
       frm.Controls(strOptionGroup).Enabled = False
       frm.Controls(strOptionGroup)..Locked = True
   Else
       frm.Controls(strOptionGroup).Enabled = True
       frm.Controls(strOptionGroup)..Locked = False
   End If
End Function

And then call it in the afterUpdate and On Current events:

this is the form's current event:
Code:
SetLockEnabled Me, "Frame188", "TextBox86"
SetLockEnabled Me, "Frame190", "TextBox88"
SetLockEnabled Me, "Frame192", "TextBox90"
SetLockEnabled Me, "Frame194", "TextBox92"
SetLockEnabled Me, "Frame196", "TextBox94"

Replace the control names with the correct ones (except the ME part - leave that exactly as it shows).
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Where do I put the top code? So I place the bottom code in both afterupdate and oncurrent correct? Is there anything else that I need to change in these codes. Don't I need to change the strTextBox and strOptionGroup with exact text box and option group? Sorry for the noob question. Thanks Bob!
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Where do I put the top code? So I place the bottom code in both afterupdate and oncurrent correct? Is there anything else that I need to change in these codes. Don't I need to change the strTextBox and strOptionGroup with exact text box and option group? Sorry for the noob question. Thanks Bob!

The top part goes into a standard module. You can put it in a new module or in an existing one. But it isn't in a form or report module. Name the module (if new) to anything BUT NOT the name of the function.

The top code you are putting in the standard module, you do not need to change anything on. It is good to go.

The bottom code (which I showed for use in the form's On Current event) all you need to change is the actual names of the option groups and text boxes.

So for example I had:

SetLockEnabled Me, "Frame188", "TextBox86"

So if your option group was actually named MyOptGroup and your text box was named txtSetPattern the code would change to:

SetLockEnabled Me, "MyOptGroup", "txtSetPattern"

and you would add a line for each option group/text box combination (I was assuming from your post that you had 5 option groups, each with their associated text box).

And then put the applicable single line on the After Update event of each of the text boxes.
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Thanks so much guys! So modules run automatically right? Gizmo I can't get to your link. Blocked. Thanks though.
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Thanks so much guys! So modules run automatically right?
Not sure I understand your question. Modules are things that hold procedures and functions which can be called at various times. A module can be a form module, a report module, or a standard module. The code I gave you really should be in a standard module.

What you do with procedures is have them run based on events. So in your On Current event, for example, if you call that function

SetLockEnabled Me, "Frame188", "TextBox86"

Then that procedure, SetLockEnabled, will run whenever the On Current event fires. It doesn't run "automatically" as I would understand "automatically."
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Ok, so the Afterupdate/OnCurrent calls the module then. Gotcha. Thanks for your time Bob!
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Sorry Bob! I need to place a call function in the On Current and AfterUpdate correct?

Like Call SetLockedEnabled (Me, True)
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Sorry Bob! I need to place a call function in the On Current and AfterUpdate correct?

Like Call SetLockedEnabled (Me, True)

No like

Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")

replacing YourOptionGroupName and YourTextBoxName with the actual names of your controls.
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
So for the On Current:

Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")
Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")
Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")
Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")
Call SetLockedEnabled(Me, "YourOptionGroupName", "YourTextBoxName")
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Is there anyway to make the option group unlocked right after the text is entered into the textbox.
Right now I have scroll to another record and then back to enter the option group? Thanks
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Is there anyway to make the option group unlocked right after the text is entered into the textbox.
Right now I have scroll to another record and then back to enter the option group? Thanks

Yes, I said earlier, you can put it in the AfterUpdate event of the text box. You only need the applicable one in that event though.

So for example, if your text box is named txtM1 and your option group that goes with txtM1 is named optM1 then you would use this in the txtM1 AfterUpdate event:
Code:
Call SetLockedEnabled(Me, "optM1", "txtM1")
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
Correct, It's working great Bob! But I have to scroll to the next record to save the text and then scroll back to the previous record to edit the option group. Is there another event that will make the option group unlocked right after text is entered without scrolling back and forth?
 

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Actually, you should only need to move to another control so that the text box's AFTER UPDATE event fires. Until you move to another control the text box is considered as being the old value.
 

saip15

Registered User.
Local time
Today, 09:28
Joined
Jun 22, 2009
Messages
105
That's what I thought but it's not updating after clicking on another field.

Bob, I have a thread for Switchboard examples, would you be willing to share some examples. I don't want to use the switchboard manager and can't seem to find a good starting point.
 
Last edited:

boblarson

Smeghead
Local time
Today, 08:28
Joined
Jan 12, 2001
Messages
32,059
Any chance of getting your database (minus data) to take a look and see what might be going on?
 

Users who are viewing this thread

Top Bottom