using .AddNew in nested subforms

T

TStankiewicz

I have a form with nested subforms and I'm trying to add a new record with
all the information from the previous forms. I'm only getting the field
information that triggers the nested subforms. So the forms go like this:
Main form - off employee table
Subform1 - links names and gets programs
Subform2 - gets classes from the programs
Subform3 - gets specific class information
Here's the code:

Form_frmTraining subform - 1
Option Compare Database

Private Sub Form_AfterUpdate ( )
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset ("tblTraining", dbOpenDynaset)

With rs
.AddNew
![Training Date] = [Training Date]
![Program] = [Program]
![Class] = [Class]
![SSN] = [SSN/ID]
.Update
.Bookmark = .LastModified
End With
rs.Close
Set rs = NOthing
End Sub

So Training Date comes from the last subform that has the focus (Subform3),
Class comes from Subform2 and Program comes from Subform1. I'm not getting
the SSN which comes from the Main form. What's wrong?
Thanks.
Teresa
 
D

David Lloyd

Teresa:

It is hard to know the exact issue without knowing all the fields in the
queries and how your forms and subforms are setup. However, one possible
resolution would be to do a "hard" reference to the SSN field on your main
form. For example:

![SSN] = Forms!MyMainFormName!MySSNTextBoxName

This assumes of course that the SSN field on the main form is a textbox,
however, you can make a similar reference to a combo box, etc.


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have a form with nested subforms and I'm trying to add a new record with
all the information from the previous forms. I'm only getting the field
information that triggers the nested subforms. So the forms go like this:
Main form - off employee table
Subform1 - links names and gets programs
Subform2 - gets classes from the programs
Subform3 - gets specific class information
Here's the code:

Form_frmTraining subform - 1
Option Compare Database

Private Sub Form_AfterUpdate ( )
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset ("tblTraining", dbOpenDynaset)

With rs
.AddNew
![Training Date] = [Training Date]
![Program] = [Program]
![Class] = [Class]
![SSN] = [SSN/ID]
.Update
.Bookmark = .LastModified
End With
rs.Close
Set rs = NOthing
End Sub

So Training Date comes from the last subform that has the focus (Subform3),
Class comes from Subform2 and Program comes from Subform1. I'm not getting
the SSN which comes from the Main form. What's wrong?
Thanks.
Teresa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top