Consulting

Results 1 to 3 of 3

Thread: Solved: Userform stops working after saving as a .doc

  1. #1

    Solved: Userform stops working after saving as a .doc

    So, I don't think this was a problem before, but ever since I tried to organize some of my code for this project I haven't been able to get the userform to work after the initial time it is used by opening a template. The userforms are pulled up by a macro attached to the original .dot file upon opening or creating a new file and it works when you initially open the .dot file to create a new .doc file. Unfortunately it does not work when I open an existing .doc file based on the original template and for some reason gives a file doesn't exist error when an external database is called for. I've been trying to figure this out all day and I'm guessing it's simple 'cause it was working OK before, but I can't figure out what changed or what the problem is for the life of me. The bit of code I'm posting is where this all gets stuck. The file in question (Psychiatry.mdb) exists and this works when initially running the template file it's attached to, but then later will not work after it is saved as a .doc from the template. Anyone willing to take a look?

    Thanks,

    Ryan

    [vba]
    ' This code activates the Database connection. Change
    ' the path to reflect your database.
    Set dbDatabase = OpenDatabase(ActiveDocument.Path & "C:\Documents and Settings\Ryan\My Documents\Records\Templates\Psychiatry.mdb")
    [/vba]

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'm betting that your code is not in the doc you created from the template and so it can't run....

    You would need to put an on open statement in the template also so the doc that is created can call it on open.....if your code runs from a document new on the template that would explain why it runs when the new document is created and why it won't run after that..

    show us your code for calling the macro.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3

    Fixed

    It seems that a simple change in the way I called the access database was all that was the trouble. Still seems strange as it was working until I tried to clean up the code a bit. I honestly can't tell you what exactly it was that I had changed between the working and not working part of the whole thing. Here is the code after I made the change:

    [vba]
    ' This code activates the Database connection. Change
    ' the path to reflect your database.
    Set dbDatabase = OpenDatabase("C:\Documents and Settings\Ryan\My Documents\Records\Templates\Psychiatry.mdb")
    [/vba]
    As for the code to call the macro, here is what I am using:

    [vba]
    Private Sub Document_New()
    frmselectnote.Show
    End Sub

    Private Sub Document_Open()
    frmselectnote.Show
    End Sub
    [/vba]
    This code is in the Microsoft Word Objects --> ThisDocument part.

    Anyway, even though what I have now seems to work, any info as to why it didn't before or if there's a better way to call the userform that I'm using on opening a document or starting a new one then I'm all ears.

    Thanks,

    Ryan

Posting Permissions

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