Solved

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

Posted on 2004-09-14
7
355 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now