Transfer field data from a main & sub form

D

Dale G

Hi does anyone know how I would transfer data to my word template from a sub
form that is on my main form?
I’m able to receive the main form data using this code, behind a button.
Dim oWord As New Word.Application

With oWord
.Documents.Add "C:\Documents and Settings\Employee Details.dot"

.Selection.GoTo wdGoToBookmark, , , "bmkEmployeePhoto"
.Selection.InlineShapes.AddPicture FileName:= _
Me.ImagePath, LinkToFile:=False
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeFirstName"
.Selection.TypeText Me.FirstName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeLastName"
.Selection.TypeText Me.LastName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeStreet"
.Selection.TypeText Me.Address
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeCity"
.Selection.TypeText Me.City

I’ve tried;
..Selection.GoTo wdGoToBookmark, , , "bmkEmergencyContactName"
..Selection.TypeText
[Forms]![fsubEmployeeDetails2][Me.EmergencyContactFirstName]

But this does not work. Any help is appreciated.
 
D

Dirk Goldgar

Dale G said:
Hi does anyone know how I would transfer data to my word template from a
sub
form that is on my main form?
I’m able to receive the main form data using this code, behind a button.
Dim oWord As New Word.Application

With oWord
.Documents.Add "C:\Documents and Settings\Employee Details.dot"

.Selection.GoTo wdGoToBookmark, , , "bmkEmployeePhoto"
.Selection.InlineShapes.AddPicture FileName:= _
Me.ImagePath, LinkToFile:=False
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeFirstName"
.Selection.TypeText Me.FirstName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeLastName"
.Selection.TypeText Me.LastName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeStreet"
.Selection.TypeText Me.Address
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeCity"
.Selection.TypeText Me.City

I’ve tried;
.Selection.GoTo wdGoToBookmark, , , "bmkEmergencyContactName"
.Selection.TypeText
[Forms]![fsubEmployeeDetails2][Me.EmergencyContactFirstName]

But this does not work. Any help is appreciated.

If the code is running on the main form, and "fsubEmployeeDetails2" is the
name of the subform control (on the main form) that is displaying the
subform, then you would use something like this:

.Selection.TypeText
Me.[fsubEmployeeDetails2].Form![EmergencyContactFirstName]

Note that, in the above, "fsubEmployeeDetails2" must be the name of the
subform *control*, which may or may not be the same as the name of the form
object that the subform control displays.
 
D

Dale G

Thats it, awsome, thank you.

Dirk Goldgar said:
Dale G said:
Hi does anyone know how I would transfer data to my word template from a
sub
form that is on my main form?
I’m able to receive the main form data using this code, behind a button.
Dim oWord As New Word.Application

With oWord
.Documents.Add "C:\Documents and Settings\Employee Details.dot"

.Selection.GoTo wdGoToBookmark, , , "bmkEmployeePhoto"
.Selection.InlineShapes.AddPicture FileName:= _
Me.ImagePath, LinkToFile:=False
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeFirstName"
.Selection.TypeText Me.FirstName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeLastName"
.Selection.TypeText Me.LastName
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeStreet"
.Selection.TypeText Me.Address
.Selection.GoTo wdGoToBookmark, , , "bmkEmployeeCity"
.Selection.TypeText Me.City

I’ve tried;
.Selection.GoTo wdGoToBookmark, , , "bmkEmergencyContactName"
.Selection.TypeText
[Forms]![fsubEmployeeDetails2][Me.EmergencyContactFirstName]

But this does not work. Any help is appreciated.

If the code is running on the main form, and "fsubEmployeeDetails2" is the
name of the subform control (on the main form) that is displaying the
subform, then you would use something like this:

.Selection.TypeText
Me.[fsubEmployeeDetails2].Form![EmergencyContactFirstName]

Note that, in the above, "fsubEmployeeDetails2" must be the name of the
subform *control*, which may or may not be the same as the name of the form
object that the subform control displays.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Top