Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, I have a question re: locking forms/subforms & allowing edits

Status
Not open for further replies.

mistereli

Technical User
Jan 13, 2003
73
0
0
US
This is very confusing and hope I make sense in my explaination...........
I have a database that uses 2 forms and a subform. The first form and subform is used for viewing purposes only, but the way I get to the record that I want is that I've created a control text box where you type in or scroll down and choose a number to select it (all other data then populates the rest of the fields after it is selected).

But when I set the 1st form so that the records cannot be edited I can't use my search box because it won't allow me to type in it. If I change it so I CAN use the search and lock the individual fields in my subform, it works for the 1st form (viewer) but I cannot use the second form (which is the editable form) because the subform is locked for edits.

I guess my question would be, how would I lock the entire 1st form, including the subform, but will allow me to type in the search control to find the record that I need. And in the 2nd form, that will also allow me to edit the subform (cuz when you lock a subform it locks it for use in any form, right?)

I hope you all understand my question, and will appreciate any help anyone has.......by the way, I'm a beginner, so be gentle in your explainations. Thanks a bunch!
 
Mistereli,

I have used something like this to lock the controls on form open. This works to lock the controls on the main form.

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
With ctl
.SpecialEffect = 0
.Locked = True
.ForeColor = 0
End With
End If
If ctl.ControlType = acComboBox Then
With ctl
.SpecialEffect = 0
.Locked = True
.ForeColor = 0
End With
End If
If ctl.ControlType = acCheckBox Then
With ctl
.Locked = True
End With
End If
Next ctl

'Unlocks search field.
me.search.locked = false

Repeat it to lock the controls on the subform

For Each ctl In Me.SubformName.Controls
If ctl.ControlType = acTextBox Then
With ctl
.SpecialEffect = 0
.Locked = True
.ForeColor = 0
End With
End If
If ctl.ControlType = acComboBox Then
With ctl
.SpecialEffect = 0
.Locked = True
.ForeColor = 0
End With
End If
If ctl.ControlType = acCheckBox Then
With ctl
.Locked = True
End With
End If
Next ctl

You then run the same procedure with locked set to false on the change event of the search text box to unlock the form controls.

Hope this helps.

Regards
Joel
 
Thanks for all of the above. I'm going to give it a try! Thanks again!
 
I ran into a problem with the first line of the subform part - the error message pointed to the 'SubformName' part in the line 'For Each ctl In Me.SubformName.Controls'. This code gets attached to the subform form under the 'open' click under event, doesn't it? And the last part, to set the locked set back to false, gets attached to which event? Under the same main & subform forms? Do I need to change any of the options under the data tab? Sorry for all the questions and thanks for your help! I'm so close to finally finishing the design part of my project!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top