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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Data Entry Properties of Forms via Code

Status
Not open for further replies.

a98dsu98sad8sua

Technical User
Apr 5, 2005
70
CA
Hi,

I have two main forms which are essentially the same apart from some command buttons, one form to enter data, one form to view data.

These forms also contain about 8 subforms, in Data Entry mode (for the data entry form, funnily enough).

Problem is, obviously when I open my form to view records, the subforms don't update as I flick through, due to them being in data entry.

What's the easiest way to prevent this problem? Obviously I'll need to turn data entry off, but was wondering whether there's a more elegant solution than either creating 8 duplicate subforms with data entry turned off, or using about 50 lines of code to turn Data Entry off/on every time.

Thanks,

Toby
 
Have you tried creating one generic routine to accept the subform and edit the data entry property.

Private Sub Command2_Click()
'pass the form to set the property
editForm Me.Form2.Form
End Sub

Private Sub editForm(frm As Form)
frm.DataEntry = True
End Sub
Private Sub viewForm(frm As Form)
frm.DataEntry = False
End Sub

You may even want to go to one form and use a toggle button to set the edit or view of the form. This reduces code and makes life easier.
 
Hi,

There's buttons I use on the view form that I don't want on the edit form, and vice versa. :)
 
You are probably right, it does keep the code cleaner as seperate forms. You may want to put the generic routines in each of the form_load events. Then create a list of the subforms to call the sub routine. Be sure to do both forms, then you don't have to be sure the original subform has the dataentry set to true or false. This may bite you in that while editing the view form, if the subform is saved with dataentry = false, and you assume it to be true. This kind of stuff really can spoil a good day.

You could also spin the controls if you want and skip on the errors.

For each ctrl in me.controls
on error resume next
editForm ctrl.form
next ctrl

Being that only sub forms have the form property, all other controls will error out and be skipped. This way if you add or remove sub forms, the code still works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top