Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't Get Word To Open (Access 2000)

    I've created a button that opens a Word Mail Merge document. Except now it isn't working and I don't know what I did wrong. I keep getting the error "User-defined type not defined". Does anyone have any idea? The following is the code that I have behind the button.

    Private Sub DoneSelectingbtn_Click()
    On Error GoTo Err_DoneSelectingbtn_Click


    DoCmd.GoToRecord , , acLast
    MergeIt

    Exit_DoneSelectingbtn_Click:
    Exit Sub

    Err_DoneSelectingbtn_Click:
    MsgBox Err.Description
    Resume Exit_DoneSelectingbtn_Click

    End Sub

    Function MergeIt()
    Dim objWord As Word.Document
    Set objWord = GetObject("G:StudentLabels5163.doc", "Word.Document")
    ' Make Word visible.
    objWord.Application.Visible = True
    ' Set the mail merge data source as the Northwind database.
    objWord.MailMerge.OpenDataSource _
    Name:="G:WorkingCopy.mdb", _
    LinkToSource:=True, _
    Connection:="QUERY Labels Query"
    ' Execute the mail merge.
    objWord.MailMerge.Destination = wdSendToNewDocument
    objWord.MailMerge.Execute
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't Get Word To Open (Access 2000)

    Have you set a reference to the Microsoft Word 9.0 Object Library in Tools | References... (in the Visual Basic Editor)?

    If that does not help, what is the item that is highlighted when you get the error?

    By the way, you must add Set objWord = Nothing at the end of MergeIt, to release the memory used by objWord.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't Get Word To Open (Access 2000)

    Hi Hans,

    Well it seems to work fine when I have the front and back end in the same place (G:MySchoolFeesHelp). But when I move the front end to my C:My FilesWorkingCopy.mdb, it doesn't work right. It opens two more Access's and it gives me a message box saying "The database has been placed in a state by user 'Admin' on machine 'PALLISER-Jenn' that prevents it from being opened or locked." What does this mean?

    Function MergeIt()

    Dim objWord As Word.Document
    Set objWord = GetObject("G:MySchoolFeesHelpStudentLabels5163.doc ", "Word.Document")
    ' Make Word visible.
    objWord.Application.Visible = True
    ' Set the mail merge data source as the WorkingCopy database.
    objWord.MailMerge.OpenDataSource _
    Name:="c:My FilesWorkingCopy.mdb", _
    LinkToSource:=True, _
    Connection:="QUERY Labels Query"
    ' Execute the mail merge.
    objWord.MailMerge.Destination = wdSendToNewDocument
    objWord.MailMerge.Execute
    Set objWord = Nothing

    End Function

    Here's my code again--I changed the directories it was going to. It works fine when the .mdb is in the G:MySchoolFeesHelp folder along with the StudentLabels5163.doc, but it doesn't work when I move the .mdb to C:My Files.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't Get Word To Open (Access 2000)

    Don't know if it is related, but Word is known to try to open multiple copies of the database containing the source data if the database has an application name (that does not start with Microsoft Access.) You can set the application name for a database in Tools | Startup...

    Does your database have a non-blank application name? If so, does it help if you clear the name?

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't Get Word To Open (Access 2000)

    When I go into Tools | Startup, I have a blank field under Application Title, and "none" under Display Form/Page. Is this how I should have it? Can't I put "Switchboard1" in the Display Form/Page field to open up that switchboard when it starts up?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can't Get Word To Open (Access 2000)

    Yes, you can select a form in the Display Form/Page dropdown to open that form automatically when the database is opened. A switchboard form is a good choice.

    I don't know why you have problems with multiple instances of Access starting if the Application Title property is blank. - Oh, wait! After each design change to the database, you must close and reopen it before attempting to initiate a mail merge. When you change something in the design of a form, module etc., you lock the database exclusively, so Word cannot get at it. Closing and reopening the database should remedy that.

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't Get Word To Open (Access 2000)

    Thanks Hans. Your awesome!

Posting Permissions

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