Results 1 to 5 of 5
  1. #1
    Byrkster is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    3

    Export Data from Access to Word

    I am certain this has already been answered and please forgive my newb status. I am able to export data to a word document. I have a form to create a profile, I use that profile to create an ID Card. Everything works fine until a file is blank in access. The word document is still created however I get a message in access "Run-Time error '94': Invalid use of Null. I would like to have access ignore the blank field so I dont get the error. There are at times the information is not required to be exported. Below is my VB, again I am very new to access but realize the potential of using this software. any help would be greatly appreciated.

    Private Sub CCSOFC_Click()
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim filepath As String
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Open("CCSOFC.doc", , True)
    With doc
    wrdDoc.FormFields("Rank").Result = (Me!Rank)
    wrdDoc.FormFields("Name").Result = (Me!Name)
    wrdDoc.FormFields("CertNumber").Result = (Me!CertNumber)
    wrdDoc.FormFields("Agency").Result = (Me!Agency)
    wrdDoc.FormFields("ContactNumber").Result = (Me!ContactNumber)
    wrdDoc.FormFields("IssueDate").Result = (Me!ORDate)
    wrdDoc.FormFields("ExpDate").Result = (Me!ExpDate)
    wrdApp.Visible = True
    wrdApp.Activate
    End With
    Set doc = Nothing
    Set appWord = Nothing
    Exit Sub
    errHandler:
    MsgBox Err.Number & ": " & Err.Description
    End Sub

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    Check out the NZ function. You can use this to wrap the field and replace null with a " " space or a "N/A" or something. Or you could do an If/then around each statement as in: If Not IsNull(FieldName) then....

    Or you could fundamentally set up the tables with fields with a default value so that nulls do not exist.

  3. #3
    Byrkster is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    3
    Quote Originally Posted by NTC View Post
    Check out the NZ function. You can use this to wrap the field and replace null with a " " space or a "N/A" or something. Or you could do an If/then around each statement as in: If Not IsNull(FieldName) then....

    Or you could fundamentally set up the tables with fields with a default value so that nulls do not exist.
    Thank you for replying to my post, I wanted to add the if/then to ignore a blank field, not sure how to set that up. I create the ID cards for our Office, I want to be able to pull the images from access to word, not sure how to do that either I am learning, but google can only show so much...

    Again thanks for your help..
    Rob

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    Why do you not make an Access report? rather than all this linking to Word?

  5. #5
    Byrkster is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    3
    Quote Originally Posted by NTC View Post
    Why do you not make an Access report? rather than all this linking to Word?

    I did just that, the form had been created in word, and was part or our policy, I dumped the document and now have access printing everything, cut out tons of work.

    But thanks you for your feed back, much appreciated.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 01-11-2016, 02:13 AM
  2. Using Access Data in Word Doc
    By Jacob.T in forum Import/Export Data
    Replies: 2
    Last Post: 07-26-2014, 07:10 AM
  3. Word VBA Data from Access
    By JulieK in forum Programming
    Replies: 14
    Last Post: 07-03-2014, 03:40 AM
  4. export access report to word
    By afshin in forum Access
    Replies: 6
    Last Post: 01-15-2014, 12:11 AM
  5. Export to Word
    By Monterey_Manzer in forum Import/Export Data
    Replies: 0
    Last Post: 12-20-2012, 02:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums