Solved

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

Posted on 2004-09-14
7
354 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ust html in ms/access WebBrowswer 11 45
Numbers are exporting as text 5 27
DATETIMEOFFSET feature 1 0
Stored Procedure 2 0
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 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

12 Experts available now in Live!

Get 1:1 Help Now