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

Can edit data in subforms 1

Status
Not open for further replies.

deweb

Technical User
Jun 27, 2002
23
US
I have a form for with two subforms that I use for data entry into my trainings database. The forms and subforms are bound and the tables are related. The main form has the following properties:

Allow Edits = yes
Allow Deletions = yes
Allow Additions = yes
Allow Data entry = yes

The subforms have the following properties:

Allow Edits = yes
Allow Deletions = yes
Allow Additions = yes
Allow Data entry = no

The form and subforms work fine and I'm able to enter data correctly.

I also have a similar form (that was based on the above form with a few modifications) that I use for viewing the data only.

The properties for the view only form are:

Allow Edits = No
Allow Additions = No
Allow Deletions = No
Allow Data Entry = No

The subforms and their properties are the same as listed above.

This works fine and neither the main form nor the subforms are editable.

However, there is a command button, "Edit Record," on the footer of the main form with the following code in the On Click event:

Code:
 Private Sub EditRecord_Click()

    Me.AllowEdits = True        ' Make the ViewEditTrainings form editable.
    TrainingTitle.SetFocus      ' Move to the TrainingTitle field.
    
End Sub


MY PROBLEM IS the main form becomes editable, but the subforms are not. In fact the record saves as soon as I try to tab out of the last field on the main form.

How do I correct this?

Thanks.

Denise
 
1. The record on a form will automatically save whenever that record loses focus, whether that be by Tabbing past the last field on form, closing the form, changing record, or entering/leaving a subform.
You can make a slight change to the properties of your form to prevent the form from moving onto the next record when you tab past the last field on your form.
Change the form's "Cycle" property to "Current Record".


2. You can try explicitly informing the subform to allow edits too.

ie me.<subform name>.form.allowedits = True



Alec Doughty
Doughty Consulting P/L

&quot;Life's a competition. Play hard, but play fair&quot;
 
Well, we're getting there.

When I change the &quot;Cycle&quot; property to &quot;Current Record.&quot; I can tab out of the main form without it attempting to save, but I'm unable to edit the subforms. When I include the code to explicitly inform the subform to allow edits, the main form again saves when I attempt to tab into the subform. Then it tabs into the subform and it will allow me to change information that is already there but I cannot add another record.

For example, if I have two training sponsors listed, it will allow me to go into the combo box and choose a different sponsor, but I can't add a third. Instead, it tabs over to the next subform.

Any other suggestions?

Thanks,

Denise
 
Try setting the Allow Data Entry = Yes as the subforms default.

And in the same code that you set the mainforms AllowEdits value set the subforms AllowEdits and/or AllowAdditions.

IE

Private Sub EditRecord_Click()

Me.AllowEdits = True ' Make the ViewEditTrainings form editable.
Me![[<Subform Name>]].Form.AllowEdits = True
TrainingTitle.SetFocus ' Move to the TrainingTitle field.

End Sub


Alec Doughty
Doughty Consulting P/L

&quot;Life's a competition. Play hard, but play fair&quot;
 
Thank you.

For some reason when I set the Allow Data Entry = Yes as the subform's default, the text fields disappeared in the subform. (Go figure.)

But, when I used the code you suggested, it worked!

Have a star!

Denise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top