chainedtodesk
Programmer
i had the following code working okay in an .MDB but i have now moved this to an .ADP and i cannot figure out the following error. i get "user defined type not defined"
'Open Word, import the text to the bookmarks and display the letter
Set objWord = New Word.Application
objWord.Visible = False 'was True
'Open Your Recordset and move to the first record
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Invitations_ToGo", dbOpenDynaset)
rs.MoveFirst
'Loop through each record of the Rs, inserting each field of the record into a Bookmark in the template
Do Until rs.EOF
Set objWordDoc = objWord.Documents.Add(Template:="C:\DM_Inputs\Invite.dot", NewTemplate:=False)
With objWordDoc
.Activate '<------- important
.Bookmarks("InviteInfo").Range.Text = rs![First Name] & " " & rs![Last Name] & vbCrLf & rs![Address 1] & " " & rs![Address 2] & vbCrLf & rs!City & ", " & rs!State & " " & rs!Zipcode & vbCrLf & vbCrLf & vbCrLf & rs!Datesent & vbCrLf & vbCrLf
End With
'Save the letter to the desired folder
Dim strhdr1 As String
strhdr1 = rs![Last Name] & "_" & rs![First Name]
objWordDoc.SaveAs filename:="c:\DM_Outputs\Invitation_" & strhdr1 & ".doc"
objWordDoc.close
Set objWordDoc = Nothing
rs.MoveNext
Loop
objWord.Quit
Set objWord = Nothing
thanks for any advice
'Open Word, import the text to the bookmarks and display the letter
Set objWord = New Word.Application
objWord.Visible = False 'was True
'Open Your Recordset and move to the first record
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Invitations_ToGo", dbOpenDynaset)
rs.MoveFirst
'Loop through each record of the Rs, inserting each field of the record into a Bookmark in the template
Do Until rs.EOF
Set objWordDoc = objWord.Documents.Add(Template:="C:\DM_Inputs\Invite.dot", NewTemplate:=False)
With objWordDoc
.Activate '<------- important
.Bookmarks("InviteInfo").Range.Text = rs![First Name] & " " & rs![Last Name] & vbCrLf & rs![Address 1] & " " & rs![Address 2] & vbCrLf & rs!City & ", " & rs!State & " " & rs!Zipcode & vbCrLf & vbCrLf & vbCrLf & rs!Datesent & vbCrLf & vbCrLf
End With
'Save the letter to the desired folder
Dim strhdr1 As String
strhdr1 = rs![Last Name] & "_" & rs![First Name]
objWordDoc.SaveAs filename:="c:\DM_Outputs\Invitation_" & strhdr1 & ".doc"
objWordDoc.close
Set objWordDoc = Nothing
rs.MoveNext
Loop
objWord.Quit
Set objWord = Nothing
thanks for any advice