PDA

View Full Version : Solved: Userform stops working after saving as a .doc



rbrewington
08-07-2008, 03:23 PM
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


' 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")

lucas
08-07-2008, 04:28 PM
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.

rbrewington
08-07-2008, 05:57 PM
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:


' 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")

As for the code to call the macro, here is what I am using:


Private Sub Document_New()
frmselectnote.Show
End Sub

Private Sub Document_Open()
frmselectnote.Show
End Sub

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