jstoddard
Dec 27 2007, 11:21 AM
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
theDBguy
Dec 27 2007, 11:49 AM
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
HiTechCoach
Dec 27 2007, 12:01 PM
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.
jstoddard
Dec 27 2007, 12:43 PM
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
theDBguy
Dec 27 2007, 01:06 PM
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?
jstoddard
Dec 27 2007, 01:11 PM
There is nothing in the Open event. The controls don't unlock when the current is a new record.
Aquadevel
Dec 27 2007, 01:18 PM
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
jstoddard
Dec 27 2007, 01:31 PM
Aqua,
That did it.
Thanks
Aquadevel
Dec 27 2007, 01:32 PM
You are welcome,
Good luck with your project.
jstoddard
Dec 27 2007, 02:03 PM
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.
jstoddard
Dec 27 2007, 02:26 PM
I found a solution.
Instead of locking the controls on the subform I disabled the subform itself.
Thanks to everyone for the help.
theDBguy
Dec 27 2007, 02:28 PM
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.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.