Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Opening Word from Access - Final Details!


Message #1 by "Tammy Tappan" <GRTappan@e...> on Tue, 27 Nov 2001 22:08:51
Okay, 3 last minor details:



1) When I run the procedure in the Immediate Window, everything works 

okay; however, I'm returned to the Immediate Window rather than remaining 

on the document - will this change once the procedure is assigned to 

something in the database?



2) Speaking of "something in the database", I'd like this procedure to run 

from a simple command button - do I assign the module directly to the 

button? If so, how? Or, should I do a macro to run the module, & then 

assign the macro to the button?



3) When I closed the document, it seemed to have disappeared? I assigned 

it to the appropriate folder, but it wasn't there. I tried to reopen it 

from Start>Documents - couldn't find it. What happened? Word let me close 

the document without an additional save.



+Tammy



> Private Const m_strDIR As String = "K:\DATA\PRIVATE\Iscs\Templates\"

>  Private Const m_strTEMPLATE As String 

> "ServiceCenterUserIDRequestForm.dot"

> 

> 

> Public Sub CreateSCIDRequestDoc()

>     Static WordObj As Word.Application

>     Dim strSaveDir As String

>     dim StrFileName As String

> 

>     ' Directory to save the file _

> 	Do not save it in the Templates folder _

> 	Place it in a completely folder. _

> 	I placed the file in My Documents, in _

> 	the Test directory		

>     strSaveDir = "C:\Documents and Settings\Administrator\My

> Documents\Test\"

>     strFileName = "User ID Request for Papparuff.doc"

>     

>     Set WordObj = Nothing

>     Set WordObj = CreateObject("Word.Application")

>     

>     ' Open the template

>     WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

>     

>     'Enable viewing the Word session and its document

>     WordObj.Visible = True

>     ' Save the template to a .doc file before user can use it.

>     ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

> 

>     ' You do not have to set WordObj to nothing because _

> 	when the user closes Word, it's instance will be _

> 	destroyed.

> 

> End Sub

Message #2 by "John Ruff" <papparuff@c...> on Wed, 28 Nov 2001 06:13:10 -0800
Tammy



On the button's Click event, call the procedure



Private Sub cmdOpenWord_Click()



	Call CreateSCIDRequestDoc



End sub



Let's see if it works as advertised.

You also need to change 

Private Const m_strDIR As String = "K:\DATA\PRIVATE\Iscs\Templates\" 



to



Public Const m_strDIR As String = "K:\DATA\PRIVATE\Iscs\Templates\"



And



Private Const m_strTEMPLATE As String 

"ServiceCenterUserIDRequestForm.dot 



to



Public Const m_strTEMPLATE As String 

"ServiceCenterUserIDRequestForm.dot



John Ruff - The Eternal Optimist :-)







-----Original Message-----

From: Tammy Tappan [mailto:GRTappan@e...] 

Sent: Tuesday, November 27, 2001 10:09 PM

To: Access

Subject: [access] Opening Word from Access - Final Details!





Okay, 3 last minor details:



1) When I run the procedure in the Immediate Window, everything works 

okay; however, I'm returned to the Immediate Window rather than

remaining 

on the document - will this change once the procedure is assigned to 

something in the database?



2) Speaking of "something in the database", I'd like this procedure to

run 

from a simple command button - do I assign the module directly to the 

button? If so, how? Or, should I do a macro to run the module, & then 

assign the macro to the button?



3) When I closed the document, it seemed to have disappeared? I assigned



it to the appropriate folder, but it wasn't there. I tried to reopen it 

from Start>Documents - couldn't find it. What happened? Word let me

close 

the document without an additional save.



+Tammy



> Private Const m_strDIR As String = "K:\DATA\PRIVATE\Iscs\Templates\"  

> Private Const m_strTEMPLATE As String = 

> "ServiceCenterUserIDRequestForm.dot"

> 

> 

> Public Sub CreateSCIDRequestDoc()

>     Static WordObj As Word.Application

>     Dim strSaveDir As String

>     dim StrFileName As String

> 

>     ' Directory to save the file _

> 	Do not save it in the Templates folder _

> 	Place it in a completely folder. _

> 	I placed the file in My Documents, in _

> 	the Test directory		

>     strSaveDir = "C:\Documents and Settings\Administrator\My 

> Documents\Test\"

>     strFileName = "User ID Request for Papparuff.doc"

>     

>     Set WordObj = Nothing

>     Set WordObj = CreateObject("Word.Application")

>     

>     ' Open the template

>     WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

>     

>     'Enable viewing the Word session and its document

>     WordObj.Visible = True

>     ' Save the template to a .doc file before user can use it.

>     ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

> 

>     ' You do not have to set WordObj to nothing because _

> 	when the user closes Word, it's instance will be _

> 	destroyed.

> 

> End Sub



---

You are currently subscribed to access as: papparuff@c... To

unsubscribe send a blank email to $subst('Email.Unsub')



Read the future with ebooks at B&N

http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&catego

ryid=rn_ebooks







Message #3 by "Tammy Tappan" <GRTappan@e...> on Wed, 28 Nov 2001 16:21:45
Well, John - you nailed 1 & 2 no problem!!! As for #3, finding the file: I 

think there's something wrong in the SaveAs part. 



Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

    

    strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

    strFileName = "User ID Request for" & ".doc"



    Set WordObj = Nothing

    Set WordObj = CreateObject("Word.Application")

    

    WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

    

    WordObj.Visible = True

    

    ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

    



End Sub

It's not saving it as a document called "User ID Request for.doc", & 

putting it in the folder named SCUserIDRequests; it's called the 

document "SCUserIDRequests User ID Request for.doc", & putting in the next 

folder up (ServiceCenter). ??



(Stay tuned - I'm going to try to update the code to automatically fill in 

info based on the info on the active form where the button is located!)



+Tammy



Message #4 by "John Ruff" <papparuff@c...> on Wed, 28 Nov 2001 08:36:54 -0800
Oops!



Change     

strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

To

strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests\"



I forgot to add a back-slash \ after SCUserIDRequests





John Ruff - The Eternal Optimist :-)







-----Original Message-----

From: Tammy Tappan [mailto:GRTappan@e...] 

Sent: Wednesday, November 28, 2001 4:22 PM

To: Access

Subject: [access] RE: Opening Word from Access - Final Details!





Well, John - you nailed 1 & 2 no problem!!! As for #3, finding the file:

I 

think there's something wrong in the SaveAs part. 



Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

    

    strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

    strFileName = "User ID Request for" & ".doc"



    Set WordObj = Nothing

    Set WordObj = CreateObject("Word.Application")

    

    WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

    

    WordObj.Visible = True

    

    ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

    



End Sub

It's not saving it as a document called "User ID Request for.doc", & 

putting it in the folder named SCUserIDRequests; it's called the 

document "SCUserIDRequests User ID Request for.doc", & putting in the

next 

folder up (ServiceCenter). ??



(Stay tuned - I'm going to try to update the code to automatically fill

in 

info based on the info on the active form where the button is located!)



+Tammy





---

You are currently subscribed to access as: papparuff@c... To

unsubscribe send a blank email to $subst('Email.Unsub')



Read the future with ebooks at B&N

http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&catego

ryid=rn_ebooks







Message #5 by "Tammy Tappan" <GRTappan@e...> on Wed, 28 Nov 2001 17:21:11
I should have caught that, I know at least that much!



Here's an interesting occurance: The procedure works every other time! 

It's in the save part - it only looks to do the SaveAs every other time; 

the times it doesn't, I get a Run-time error: '462': The remote server 

machine does not exist or is unavailable." The Debug points to the line:



ActiveDocument.SaveAs FileName:=strSaveDir & strFileName



Is this our system, or is it because I keep deleting the document after 

I've tested the button?



+Tammy



> Oops!

> 

> Change     

> strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

> To

> strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests\"

> 

> I forgot to add a back-slash \ after SCUserIDRequests

> 

> 

> John Ruff - The Eternal Optimist :-)

> 

Message #6 by "Gerald, Rand" <RGerald@u...> on Wed, 28 Nov 2001 16:45:03 -0600
Tammy:



You're missing a few characters.



Looking at:



    strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

    strFileName = "User ID Request for" & ".doc"



and



     ActiveDocument.SaveAs FileName:=strSaveDir & strFileName



You will get the file name as:

 "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequestsUser ID Request

for.doc"



Change:

    ActiveDocument.SaveAs FileName:=strSaveDir & "\" & strFileName



The extra five characters:    "\" &



Make all the difference.



Rand



-----Original Message-----

From: Tammy Tappan [mailto:GRTappan@e...]

Sent: Wednesday, November 28, 2001 10:22 AM

To: Access

Subject: [access] RE: Opening Word from Access - Final Details!



Well, John - you nailed 1 & 2 no problem!!! As for #3, finding the file: I

think there's something wrong in the SaveAs part.



Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

   

    strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

    strFileName = "User ID Request for" & ".doc"



    Set WordObj = Nothing

    Set WordObj = CreateObject("Word.Application")

   

    WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

   

    WordObj.Visible = True

   

    ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

   



End Sub

It's not saving it as a document called "User ID Request for.doc", &

putting it in the folder named SCUserIDRequests; it's called the

document "SCUserIDRequests User ID Request for.doc", & putting in the next

folder up (ServiceCenter). ??



(Stay tuned - I'm going to try to update the code to automatically fill in

info based on the info on the active form where the button is located!)



+Tammy










Read the future with ebooks at B&N

http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&categoryid

=rn_ebooks

Message #7 by "John Ruff" <papparuff@c...> on Wed, 28 Nov 2001 15:32:38 -0800
I'm not sure Tammy, but try something for me.  Rem that line,

ActiveDocument.SaveAs... And run the program.  When the template opens,

close it.  Does it ask you if you want to save document1?  If it does,

say yes and tell it where to save it, the close word.  Then try to open

it again through your program.  Let me know what you come up with.



John Ruff - The Eternal Optimist :-)







-----Original Message-----

From: Tammy Tappan [mailto:GRTappan@e...] 

Sent: Wednesday, November 28, 2001 5:21 PM

To: Access

Subject: [access] RE: Opening Word from Access - Final Details!





I should have caught that, I know at least that much!



Here's an interesting occurance: The procedure works every other time! 

It's in the save part - it only looks to do the SaveAs every other time;



the times it doesn't, I get a Run-time error: '462': The remote server 

machine does not exist or is unavailable." The Debug points to the line:



ActiveDocument.SaveAs FileName:=strSaveDir & strFileName



Is this our system, or is it because I keep deleting the document after 

I've tested the button?



+Tammy



> Oops!

> 

> Change     

> strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

> To

> strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests\"

> 

> I forgot to add a back-slash \ after SCUserIDRequests

> 

> 

> John Ruff - The Eternal Optimist :-)

> 



---

You are currently subscribed to access as: papparuff@c... To

unsubscribe send a blank email to $subst('Email.Unsub')



Read the future with ebooks at B&N

http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&catego

ryid=rn_ebooks







Message #8 by "Tammy Tappan" <GRTappan@e...> on Thu, 29 Nov 2001 12:38:08
I know the answer without trying! It doesn't ask to save anything when I close the .dot; it just 

closes it & doesn't save a document - returns to Access with the run-time error.  What does 

"rem that line" mean?



Also - will it make a difference, do you think, when I add the code to the file name to specifiy 

that it will put the name of the person on the active form into the document name? I have to 

look up the exact coding (I'm at home, book's at work!), but it will be something like



"User ID Request for" & (code to indicate the name on the current form) & ".doc"



Do you think adding that piece in, to make each document unique, will help the error?



+Tammy



> I'm not sure Tammy, but try something for me.  Rem that line,

> ActiveDocument.SaveAs... And run the program.  When the template opens,

> close it.  Does it ask you if you want to save document1?  If it does,

> say yes and tell it where to save it, the close word.  Then try to open

> it again through your program.  Let me know what you come up with.

> 

> John Ruff - The Eternal Optimist :-)

> 

> 

> 

> -----Original Message-----

> From: Tammy Tappan [mailto:GRTappan@e...] 

> Sent: Wednesday, November 28, 2001 5:21 PM

> To: Access

> Subject: [access] RE: Opening Word from Access - Final Details!

> 

> 

> I should have caught that, I know at least that much!

> 

> Here's an interesting occurance: The procedure works every other time! 

> It's in the save part - it only looks to do the SaveAs every other time;

> 

> the times it doesn't, I get a Run-time error: '462': The remote server 

> machine does not exist or is unavailable." The Debug points to the line:

> 

> ActiveDocument.SaveAs FileName:=strSaveDir & strFileName

> 

> Is this our system, or is it because I keep deleting the document after 

> I've tested the button?

> 

> +Tammy

> 

> > Oops!

> > 

> > Change     

> > strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests"

> > To

> > strSaveDir = "K:\DATA\PRIVATE\Iscs\ServiceCenter\SCUserIDRequests\"

> > 

> > I forgot to add a back-slash \ after SCUserIDRequests

> > 

> > 

> > John Ruff - The Eternal Optimist :-)

> > 

> 

> ---

> You are currently subscribed to access as: papparuff@c... To

> unsubscribe send a blank email to $subst('Email.Unsub')

> 

> Read the future with ebooks at B&N

> http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&catego

> ryid=rn_ebooks

> 

> 

> 

Message #9 by aland@a... on Fri, 30 Nov 2001 23:43:47
I have what may be a silly question, but here goes ...

When you set up the string that defines the file name to save as, do you 

include beginning and ending quotation marks, to ensure that the embedded 

spaces in the file name won't cause you grief?

... AL

  Return to Index