Connecting Tech Pros Worldwide Help | Site Map

Not allowing edit in a main form disabling edits in a subform

Familiar Sight
 
Join Date: Apr 2007
Location: Lebanon
Posts: 211
#1: 3 Weeks Ago
Dear Friend


Working on access 2007 sp2.

My form is consisting from a form and a subform.

while i am using the alowedits=no option on the property of the main form it is preventing me to edit my subform.

Is there any method where I will be able to stop edit in the main form while the subform still editable ?

I don't want to go through VBA because I do have many attributes and action on this forms...

Thank you in advance

Regards
best answer - posted by missinglinq
You'll need to loop thru the controls on the main form, and if the control type is not subform, lock it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim ctrl As Control
  3.  
  4. For Each ctrl In Me.Controls
  5.  If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then
  6.    ctrl.Locked = True
  7.  End If
  8. Next
  9.  
  10. End Sub
This locks textboxes and comboboxes, if you have other controls on the main form that need locking, you simply add them to the

If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox)

line in a like manner.

Linq ;0)>
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,668
#2: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


Wassim, Your question seems to be the opposite of the title. What is it you're asking about exactly?
Familiar Sight
 
Join Date: Apr 2007
Location: Lebanon
Posts: 211
#3: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


Sorry About the subject I was trying to say
while I disable edit in the main form, access is disabling edits in the subform too

the question is:

Is there any method where I will be able to stop edit in the main form while the subform still editable ?

Thank you
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#4: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


You'll need to loop thru the controls on the main form, and if the control type is not subform, lock it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Dim ctrl As Control
  3.  
  4. For Each ctrl In Me.Controls
  5.  If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then
  6.    ctrl.Locked = True
  7.  End If
  8. Next
  9.  
  10. End Sub
This locks textboxes and comboboxes, if you have other controls on the main form that need locking, you simply add them to the

If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox)

line in a like manner.

Linq ;0)>
Megalog's Avatar
Expert
 
Join Date: Sep 2007
Posts: 268
#5: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


Go to the subform's form properties, and be sure the Allow Edits is set to YES.
I just tested this on a new form/subform and it worked fine with the main form locked down, but I had to then change the subform's property back to allow edits there.

If you are locking down the main form with VBA, then basically follow that statement with another line to ENABLE the edits for the subform. It may be that access is automatically propogating that property from the main form, to the subform?
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#6: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


If AllowEdits is set to No on the main form, then no control on the main form can be editied, including the subform control! That's why the only way to handle this is as I've suggested. You have to lock all controls on the main form except the subform control.

Linq ;0)>
Megalog's Avatar
Expert
 
Join Date: Sep 2007
Posts: 268
#7: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


I stand corrected, Linq is right as usual ;)

I could've sworn I had it working in a test db.. then I created one from scratch and couldnt get it to work as I had said.
Familiar Sight
 
Join Date: Apr 2007
Location: Lebanon
Posts: 211
#8: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


Thanks all. I am doing the loop to lock all my control..

Regards
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#9: 3 Weeks Ago

re: Not allowing edit in a main form disabling edits in a subform


Glad we could help!

Linq ;0)>
Reply


Similar Microsoft Access / VBA bytes