Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New England (Connecticut)
    Posts
    200
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Moving Data from Acess to Word (office 2003)

    Hi all, I am trying to move data from Access to word using a word template and bookmarks as insertion points. The code works great except when a field in Access is empty or null. I am trying to test for the null and substitute a variable when this happens. However, no matter what I try I get a "Object Variable or With Variable not set" error when the field is not filled in. If the field contains data, the code runs fine. How can I test for data and substitute my own data. A snippet of the code is below:


    Selection.GoTo What:=wdGoToBookmark, Name:="vContractNumber"

    With rst
    Do While Not .EOF

    If ![ContractModNumber] = "" Then
    ![ContractModNumber] = "Basic"
    SaveName = ![contractnumber] & " " & ![ContractModNumber]
    End If


    SaveName = ![contractnumber] & " " & ![ContractModNumber]

    'Insert data into labels
    Selection.TypeText Text:=![contractnumber]
    Selection.GoTo What:=wdGoToBookmark, Name:="vACO"
    Selection.TypeText Text:=![ACOCode]

    Selection.GoTo What:=wdGoToBookmark, Name:="vTaskNum"
    If ![JobTaskOrderNumber] = "" Then
    ![JobTaskOrderNumber] = "NONE"
    Selection.TypeText Text:=![JobTaskOrderNumber]
    End If
    Selection.TypeText Text:=![JobTaskOrderNumber]

    Selection.GoTo What:=wdGoToBookmark, Name:="vTypeofContract"
    Selection.TypeText Text:=![TypeofContract]


    .MoveNext
    Loop


    .Close
    End With

    It is in the "SaveName" Line where the code bombs. When I hit debug and hang the cursor over
    "![ContractModNumber]", is where I see the error.

    Hopefully someone can point me in the right direction to test for this case.

    Thanks
    Kevin
    Kevin

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Moving Data from Acess to Word (office 2003)

    Try the IsNull function rather that testing = to ""

    eg.
    If IsNull(![JobTaskOrderNumber]) Then

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Moving Data from Acess to Word (office 2003)

    Where did you declare SaveName? If it is a variable, you need a dim statement. If it is a field, you need an indicator to tell Access it isn't a variable. If it is a control, the name is apparently misspelled.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •