Solved

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

Posted on 2004-09-14
7
358 Views
Last Modified: 2008-03-17
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
Comment
Question by:bastille2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 250 total points
ID: 12057902
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
 
LVL 16

Expert Comment

by:Nestorio
ID: 12057951
Private Sub txtSSN_AfterUpdate()
Form_sfrm.AllowEdits = False
' Run Macro
Form_sfrm.AllowEdits = True
End Sub
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 12057968
Correction:

Private Sub txtSSN_AfterUpdate()
Form_sfrm.AllowEdits = True
' Run Macro
Form_sfrm.AllowEdits = False
End Sub
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:bastille2
ID: 12058218
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
 

Author Comment

by:bastille2
ID: 12058243
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12058285
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
 

Author Comment

by:bastille2
ID: 12058555
shanesuebsahakarn,

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

Bob
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question