• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

Lock and un-lock form based on a control event.

Hi,

I have an Access database of employee records.  There is a form where the user will enter a social security number.  The after update event of that box will cause a macro to run which will fill in some of the fields on the form and on a sub form.  What I’m having trouble with is the following:  Upon opening the form, I want the sub form to be locked so the user can’t enter data in it until after a SSN has been entered on the main form.  After a SSN has been entered, I want the sub form to unlock and the SSN field to become locked so the user can’t change it again.  How do I do this?

Thanks,
Bob
0
bastille2
Asked:
bastille2
  • 3
  • 2
  • 2
1 Solution
 
shanesuebsahakarnCommented:
That's fairly straightforwards. In the OnOpen (or better yet, in the OnCurrent) event, put this:

Me!My
Me!MySubformControl.Enabled=False

In the AfterUpdate event of the textbox where the SSN is entered, put:
Me!MySubformControl.Enabled=True
Me!txtMySSNTextbox.Locked=True

MySubformControl is the name of the control where the subform is held, and txtMySSNTextbox is the name of the SSN textbox (rather obviously :-)
0
 
NestorioCommented:
Private Sub txtSSN_AfterUpdate()
Form_sfrm.AllowEdits = False
' Run Macro
Form_sfrm.AllowEdits = True
End Sub
0
 
NestorioCommented:
Correction:

Private Sub txtSSN_AfterUpdate()
Form_sfrm.AllowEdits = True
' Run Macro
Form_sfrm.AllowEdits = False
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bastille2Author Commented:
shanesuebsahakarn,

In your example you use both enabled and locked.  My understanding is that locked will keep the item visible but will not allow edits, enabled will grey it out.  I would like no change to the appearance of things, just allow/prevent changes.  Can I use locked for both field and subform?
0
 
bastille2Author Commented:
Sorry, forgot something...I'm not sure of the difference between OnOpen and OnCurrent.  Could you point me to a list of event definitions?
0
 
shanesuebsahakarnCommented:
OnOpen only fires once (when the form is opened), but OnCurrent fires every time you move onto another record. You can certainly use Locked for both the field and the subform if you want, it will achieve what you need.
0
 
bastille2Author Commented:
shanesuebsahakarn,

Whoo Hooo!  Worked like a charm.  Pleasure doing business with you.

Bob
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now