My Assistant
![]() ![]() |
|
|
Dec 27 2007, 11:21 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 290 |
I have a form with an embeded subform. When The form is opened to an existing record I want all controls on both the main form and subform locked. When a new record is opened on the form I want the controls on the subform locked until the two controls on the main form have been filled. I then want the controls on the main form locked once any control on the subform has been filled.
Is this possible and how could it be done? Thanks |
|
|
|
Dec 27 2007, 11:49 AM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 47,958 From: SoCal, USA |
To do something like that, you could try something like this:
Lock all the controls in Design View (so they are locked when the form is opened). Then in the Current event, you can check for a NewRecord: If Me.NewRecord Then 'code to unlock the main form controls Me.Control1.Enabled = True End If Then in the AfterUpdate event of each control in the main form, you could put something like: If IsNull(Control1) And IsNull(Control2) Then 'they didn't complete both controls Else 'lock main form Me.Control1.Enabled = False 'unlock subform Me.Subform.Enabled = True End If Note: Pure Air Code HTH |
|
|
|
Dec 27 2007, 12:01 PM
Post
#3
|
|
|
UtterAccess VIP Posts: 18,396 From: Oklahoma City, Oklahoma |
I preferr to lock the controls like you request and enable/disbanle.
You can modify theDBguy's code from this: Me.Control1.Enabled = True to Me.Control1.Locked = True I like to lock the control so that the user can still set the focus on the control and search. You can also set the form's AllowEdit property.This way you do not have to set each control individually. Edited by: HiTechCoach on Thu Dec 27 12:02:45 EST 2007. |
|
|
|
Dec 27 2007, 12:43 PM
Post
#4
|
|
|
UtterAccess Addict Posts: 290 |
Thanks for the information.
I'm having a problem with the controls unlocking when in a new record. This is what I have for the OnCurrent event for the form Private Sub Form_Current() If Me.NewRecord Then 'code to unlock the main form controls Me.Transfer_From.Enabled = True Me.Transfer_To.Enabled = True End If End Sub Does this look right? Thanks for the help. Jason |
|
|
|
Dec 27 2007, 01:06 PM
Post
#5
|
|
|
Access Wiki and Forums Moderator Posts: 47,958 From: SoCal, USA |
Yes, it looks fine to me. What sort of problem are you having? Also, how is the form being opened? Are there any codes in the form's Open event?
|
|
|
|
Dec 27 2007, 01:11 PM
Post
#6
|
|
|
UtterAccess Addict Posts: 290 |
There is nothing in the Open event. The controls don't unlock when the current is a new record.
|
|
|
|
Dec 27 2007, 01:18 PM
Post
#7
|
|
|
UtterAccess VIP Posts: 6,898 From: Earth... |
Jason,
The code: Me.Transfer_From.Enabled = True Me.Transfer_To.Enabled = True Enables/Disables a control To Unlock them use: Me.Transfer_From.Locked = False Me.Transfer_To.Locked = False |
|
|
|
Dec 27 2007, 01:31 PM
Post
#8
|
|
|
UtterAccess Addict Posts: 290 |
Aqua,
That did it. Thanks |
|
|
|
Dec 27 2007, 01:32 PM
Post
#9
|
|
|
UtterAccess VIP Posts: 6,898 From: Earth... |
You are welcome,
Good luck with your project. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif) |
|
|
|
Dec 27 2007, 02:03 PM
Post
#10
|
|
|
UtterAccess Addict Posts: 290 |
I have one more question and hopefully I'll have this form completed.
This is the code I have to lock the controls on the main form and unlock the controls on the sub form. If IsNull(Transfer_From) Or IsNull(Transfer_To) Then 'they didn't complete both controls Else 'lock main form Me.Transfer_From.Locked = True Me.Transfer_To.Locked = True 'unlock subform Me.Product.Locked = False Me.Quantity.Locked = False End If I get a Method or Data Member not found compile error on the Product and Quantity controls in the subform. If I comment out those two lines the controls on the main form act as they should when opening the form. Where do I go from here to get the controls on the subform unlocked? Thanks again. |
|
|
|
Dec 27 2007, 02:26 PM
Post
#11
|
|
|
UtterAccess Addict Posts: 290 |
I found a solution.
Instead of locking the controls on the subform I disabled the subform itself. Thanks to everyone for the help. |
|
|
|
Dec 27 2007, 02:28 PM
Post
#12
|
|
|
Access Wiki and Forums Moderator Posts: 47,958 From: SoCal, USA |
Sorry for the confusion. Thanks Aqua for jumping in to help.
I was hoping that you followed my initial suggestion of locking all the controls on the main form only, meaning the controls on the subform are not locked, but the subform itself will be locked at the main form. Anyway, to get down to the controls on the subform, you may try doing this: Me.SubformName.Form.Product.Locked = False HTH Edit Added: Glad you found a solution. Good luck with your project. Edited by: theDBguy on Thu Dec 27 14:28:46 EST 2007. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 04:14 PM |