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:
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 & ""
   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
      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, _
      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
      'Use this line to send immediately
   Set appWord = Nothing
   Set appOutlook = Nothing
   Exit Sub

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

End Sub
Who is Participating?

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

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.

Use the Nz function eg:

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

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

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
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.