Link Ms access with word file

HiThis question is related to:
"How to save mail merge in ms access 2007 with a specific name in word
12/20/11 03:15 PM, ID: 37317775"
new question is:
if some field in the temp1 table is empty I am getting an error.

This the code written by Helen_Feddema:
Quote
Public Sub CreateWordDocsAndEmailAsPDFs()
'Created by Helen Feddema 20-Dec-2011
'Last modified by Helen Feddema 28-Dec-2011

On Error GoTo ErrorHandler

   Dim appOutlook As New Outlook.Application
   Dim appWord As New Word.Application
   Dim strTemplatesPath As String
   Dim strTemplate As String
   Dim doc As Word.Document
   Dim rst As DAO.Recordset
   Dim prps As Object
   Dim strDocsPath As String
   Dim strSaveName As String
   Dim strShortDate As String
   Dim msg As Outlook.MailItem
   
   strShortDate = Format(Date, "m-ddd-yyyy")
   Set rst = CurrentDb.OpenRecordset("temp1")
   strDocsPath = appWord.Options.DefaultFilePath(wdDocumentsPath) & "\"
   strTemplatesPath = appWord.Options.DefaultFilePath(wdUserTemplatesPath) & "\"
   strTemplate = strTemplatesPath & "Tay.dot"
   appWord.Visible = True
   
   Do While Not rst.EOF
      Set doc = appWord.Documents.Add(strTemplate)
     
      'Fill Word doc properties with data from variables
      Set prps = doc.CustomDocumentProperties
      prps.Item("No").Value = rst![NA1]
      prps.Item("Customer").Value = rst![CUST]
      prps.Item("Amount").Value = rst![AMOUNT]
     
      'Update fields in Word document
      With appWord.Selection
         .HomeKey Unit:=wdStory
         .WholeStory
         .Fields.Update
      End With
   
      strSaveName = strDocsPath & "Tay document for " _
         & rst![CUST] & ", No. " & rst![NA1] & " on " _
         & strShortDate & ".pdf"
      Debug.Print strSaveName
      'doc.SaveAs FileName:=strSaveName, FileFormat:=wdFormatDocument
      doc.ExportAsFixedFormat OutputFileName:=strSaveName, _
         ExportFormat:=wdExportFormatPDF, _
         OpenAfterExport:=False
      doc.Close savechanges:=wdDoNotSaveChanges
      Set msg = appOutlook.CreateItem(olMailItem)
      msg.Subject = "Tay document for " & rst![CUST] _
         & ", No. " & rst![NA1]
      msg.To = "Email name"
      msg.Categories = "Tay document"
      msg.Attachments.Add strSaveName
      msg.Display
      'Use this line to send immediately
      'msg.Send
      rst.MoveNext
   Loop
     
ErrorHandlerExit:
   Set appWord = Nothing
   Set appOutlook = Nothing
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in CreateWordDocsAndEmailAsPDFs procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub
unQuote
HKH1967Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SheilsCommented:
Use the Nz function eg:

prps.Item("No").Value = Nz(rst![NA1]," ")

This function returns an alternate value when there is an error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HKH1967Author Commented:
sb9: thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.