Full Version: Run-time Error When Printing Word Documents From Path Listed In Subform
UtterAccess Discussion Forums > Microsoft® Access > Access Automation
nfilbeck
I am receiving a run-time error '13' Type mismatch when running this code. rst is a subform which lists the full file path of all documents to be printed in field "WIPath".

Dim rst As DAO.Recordset
Dim wordapp As Object
Dim WordDoc As Object

Set wordapp = CreateObject("Word.Application")

Set rst = Me.WorkOrder_sf1!WIPATH

rst.MoveFirst
Do While rst.EOF = False
Set WordDoc = wordapp.Documents.Open(rst)
WordDoc.PrintOut
WordDoc.Close (False)
rst.MoveNext
Loop

Set wordapp = Nothing
Set WordDoc = Nothing
Doug Steele
rst is not "a subform": it's a recordset. You need to refer to the specific field in the recordset, not just the recordset itself:

CODE
  Set WordDoc = wordapp.Documents.Open(rst!WIPath)


or

CODE
  Set WordDoc = wordapp.Documents.Open(rst.Fields("WIPath"))


nfilbeck
Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.