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

issue with ADP and word doc

Status
Not open for further replies.

chainedtodesk

Programmer
Feb 26, 2003
112
0
0
US
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
 
My hunch is converting to an ADP stripped your reference to Word.
 
thanks lameid that was correct, i keep forgetting to recheck those settings, after adding that back in it still errors out trying to set the recordset, is there any good documentation for .ADP? i am so use to using vba coding within the database but i am finding more and more that .ADP just will not accept.
 
Is your ADP using ADO (default) or DAO? You can have both if you want.

Your recordset is using DAO syntax and you might have to either change that to ADO or set the reference to DAO also.

What exactly is the error line?

Apart from this type of problem and minor syntax like removing rs.edit statements, you should not have any major issues with an ADP.
 
To expand on what payback wrote, you could add the DAO reference (assuming it is missing) and preface your DAO declarations with the library. For example...


Dim DB as DAO.DB
Dim RS as DAO.Recordset

Keep in mind too that the changes to switch to ADO are minimal and Microsoft's prefered way of using recordsets.

Alternatively making the DAO library come before the ADO library would work too but then you would have to preface ADO declarations (ADODB if memory serves).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top