Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Passing a field value to Word


Message #1 by "Tammy Tappan" <GRTappan@e...> on Thu, 29 Nov 2001 18:51:10
Okay, I give up! I'm trying to get Access to add the name of the person 

showing on a form to the SaveAs code for the Word document I'm creating, 

so the document will be called "User ID Request for Smith, John.doc" when 

the code runs. I've tried everything I can think of!



+Tammy



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

Public Const m_strTEMPLATE As String = "ServiceCenterUserIDRequestForm.dot"

Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

    

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

**THIS LINE**  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
Message #2 by "John Ruff" <papparuff@c...> on Thu, 29 Nov 2001 10:57:02 -0800
What's the variable's name for the person?  Your code should look like

this:



strFileName = "User ID Request for" & [Field from your form with the

person's name] & ".doc"





John Ruff - The Eternal Optimist :-)







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

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

Sent: Thursday, November 29, 2001 6:51 PM

To: Access

Subject: [access] Passing a field value to Word





Okay, I give up! I'm trying to get Access to add the name of the person 

showing on a form to the SaveAs code for the Word document I'm creating,



so the document will be called "User ID Request for Smith, John.doc"

when 

the code runs. I've tried everything I can think of!



+Tammy



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

Public Const m_strTEMPLATE As String 

"ServiceCenterUserIDRequestForm.dot"

Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

    

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

**THIS LINE**  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

---

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 Thu, 29 Nov 2001 20:40:20
Now I get a Compile error: External name not defined. Don't I have to tell 

the code to look at the current form? That's the part I'm not sure of. The 

form is called frmNewEmplSecurity6; I'd put it in the code w/a ! somewhere 

by the field name, right? And do I have to do a Dim stmt as well, to 

declare that form as a form?



+Tammy



> What's the variable's name for the person?  Your code should look like

> this:

> 

> strFileName = "User ID Request for" & [Field from your form with the

> person's name] & ".doc"

> 

> 

> John Ruff - The Eternal Optimist :-)

> 

> 

> 

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

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

> Sent: Thursday, November 29, 2001 6:51 PM

> To: Access

> Subject: [access] Passing a field value to Word

> 

> 

> Okay, I give up! I'm trying to get Access to add the name of the person 

> showing on a form to the SaveAs code for the Word document I'm creating,

> 

> so the document will be called "User ID Request for Smith, John.doc"

> when 

> the code runs. I've tried everything I can think of!

> 

> +Tammy

> 

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

> Public Const m_strTEMPLATE As String 

> "ServiceCenterUserIDRequestForm.dot"

> Public Sub CreateSCIDRequestDoc()

> 

>     Static WordObj As Word.Application

>     Dim strSaveDir As String

>     Dim strFileName As String

>     

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

> **THIS LINE**  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

> ---

> 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 #4 by "Gregory Serrano" <SerranoG@m...> on Thu, 29 Nov 2001 21:24:57
Tammy,



To elaborate on John Ruff's response, suppose you have a form open and you 

have a field called "Full Name".  Then your variable assignment should 

look like this:



strFileName = "User ID Request for " & Me.[Full Name] & ".doc"



If you have the names separated into two fields "First Name" and "Last 

Name", then it should look like this:



strFileName = "User ID Request for " & Me.[Last Name] & ", " & Me.[First 

Name] & ".doc"



Note that if the user enters a period in any of those fields, you're going 

to confuse the computer because you should only have one period in the 

file name, i.e. ".doc".  You should do error trapping.



If Instr(".",Me.[Full Name]) > 0 Then



   MsgBox "You cannot have a period in the name.  Please try again.", _

      vbExclamation, "Error!"

   Me.[Full Name].SetFocus



EndIf





Greg

Message #5 by "John Ruff" <papparuff@c...> on Thu, 29 Nov 2001 13:24:52 -0800
Tammy,



I forgot you are calling the procedure from your form so you need to

change the following:



Public sub CreateSCIDRequestDoc() to

Public sub CreateSCIDRequestDoc(strUserName as string)



strFileName = "User ID Request for" & [Field from your form with the

person's name] & ".doc" to



StrFileName = "User ID Request for " & strUserName & ".doc"



You need to change the following in your form's code.



Call CreateSCIDRequestDoc to    

Call CreateSCIDRequestDoc([Name of the User])



John Ruff - The Eternal Optimist :-)







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

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

Sent: Thursday, November 29, 2001 8:40 PM

To: Access

Subject: [access] RE: Passing a field value to Word





Now I get a Compile error: External name not defined. Don't I have to

tell 

the code to look at the current form? That's the part I'm not sure of.

The 

form is called frmNewEmplSecurity6; I'd put it in the code w/a !

somewhere 

by the field name, right? And do I have to do a Dim stmt as well, to 

declare that form as a form?



+Tammy



> What's the variable's name for the person?  Your code should look like

> this:

> 

> strFileName = "User ID Request for" & [Field from your form with the 

> person's name] & ".doc"

> 

> 

> John Ruff - The Eternal Optimist :-)

> 

> 

> 

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

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

> Sent: Thursday, November 29, 2001 6:51 PM

> To: Access

> Subject: [access] Passing a field value to Word

> 

> 

> Okay, I give up! I'm trying to get Access to add the name of the 

> person

> showing on a form to the SaveAs code for the Word document I'm

creating,

> 

> so the document will be called "User ID Request for Smith, John.doc" 

> when the code runs. I've tried everything I can think of!

> 

> +Tammy

> 

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

> Public Const m_strTEMPLATE As String = 

> "ServiceCenterUserIDRequestForm.dot"

> Public Sub CreateSCIDRequestDoc()

> 

>     Static WordObj As Word.Application

>     Dim strSaveDir As String

>     Dim strFileName As String

>     

>     strSaveDir = 

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

> **THIS LINE**  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

> ---

> 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&cate

> go

> ryid=rn_ebooks

> 

> 

> 



---

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 #6 by John Fejsa <John.Fejsa@h...> on Fri, 30 Nov 2001 09:38:04 +1100
Quick example:



strFileToSave=3D ""User ID Request for " & Me!Surname & ", " & Me!FName

objWord.ActiveDocument.SaveAs FileName:=3DstrFileToSave



That's all there is...



____________________________________________________



John Fejsa

Systems Analyst/Computer Programmer

Hunter Centre for Health Advancement

Locked Bag 10

WALLSEND NSW 2287

Phone: (02) 49246 336 Fax: (02) 49246 209

____________________________________________________



The doors we open and close each day decide the lives we live

____________________________________________________



CONFIDENTIALITY & PRIVILEGE NOTICE

The information contained in this email message is intended for the named 

addressee only.  If you are not the intended recipient you must not copy, 

distribute, take any action reliant on, or disclose any details of the 

information in this email to any other person or organisation.  If you 

have received this email in error please notify us immediately.



>>> GRTappan@e... 30/11/2001 5:51:10 >>>

Okay, I give up! I'm trying to get Access to add the name of the person

showing on a form to the SaveAs code for the Word document I'm creating,=20



so the document will be called "User ID Request for Smith, John.doc" 

when

the code runs. I've tried everything I can think of!



+Tammy



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

Public Const m_strTEMPLATE As String =3D "ServiceCenterUserIDRequestForm.do

t"

Public Sub CreateSCIDRequestDoc()



    Static WordObj As Word.Application

    Dim strSaveDir As String

    Dim strFileName As String

   

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

**THIS LINE**  strFileName =3D "User ID Request for" & ".doc"



    Set WordObj =3D Nothing

    Set WordObj =3D CreateObject("Word.Application")

   

    WordObj.Documents.Open (m_strDIR & m_strTEMPLATE)

   

    WordObj.Visible =3D True

   

    ActiveDocument.SaveAs FileName:=3DstrSaveDir & strFileName

   



End Sub



.au




Read the future with ebooks at B&N

http://service.bfast.com/bfast/click?bfmid=3D2181&sourceid=3D38934667&categ

oryid=3Drn_ebooks



This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient,
please delete it and notify the sender. Views expressed in this message are those of the individual sender, and are not necessarily
the views of Hunter Health.



Message #7 by "Tammy Tappan" <GRTappan@e...> on Thu, 29 Nov 2001 23:12:28
You are a genious! (Have I said that before?!)



Now all I need is, well, a bunch more!! But I'll do more posts as I get 

there!!



+Tammy

(very happy that, after 3 days of trying, this piece works!)



> Tammy,

> 

> I forgot you are calling the procedure from your form so you need to

> change the following:

> 

> Public sub CreateSCIDRequestDoc() to

> Public sub CreateSCIDRequestDoc(strUserName as string)

> 

> strFileName = "User ID Request for" & [Field from your form with the

> person's name] & ".doc" to

> 

> StrFileName = "User ID Request for " & strUserName & ".doc"

> 

> You need to change the following in your form's code.

> 

> Call CreateSCIDRequestDoc to    

> Call CreateSCIDRequestDoc([Name of the User])

> 

> John Ruff - The Eternal Optimist :-)

> 

> 

> 

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

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

> Sent: Thursday, November 29, 2001 8:40 PM

> To: Access

> Subject: [access] RE: Passing a field value to Word

> 

> 

> Now I get a Compile error: External name not defined. Don't I have to

> tell 

> the code to look at the current form? That's the part I'm not sure of.

> The 

> form is called frmNewEmplSecurity6; I'd put it in the code w/a !

> somewhere 

> by the field name, right? And do I have to do a Dim stmt as well, to 

> declare that form as a form?

> 

> +Tammy

> 

> > What's the variable's name for the person?  Your code should look like

> > this:

> > 

> > strFileName = "User ID Request for" & [Field from your form with the 

> > person's name] & ".doc"

> > 

> > 

> > John Ruff - The Eternal Optimist :-)

> > 

> > 

> > 

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

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

> > Sent: Thursday, November 29, 2001 6:51 PM

> > To: Access

> > Subject: [access] Passing a field value to Word

> > 

> > 

> > Okay, I give up! I'm trying to get Access to add the name of the 

> > person

> > showing on a form to the SaveAs code for the Word document I'm

> creating,

> > 

> > so the document will be called "User ID Request for Smith, John.doc" 

> > when the code runs. I've tried everything I can think of!

> > 

> > +Tammy

> > 

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

> > Public Const m_strTEMPLATE As String = 

> > "ServiceCenterUserIDRequestForm.dot"

> > Public Sub CreateSCIDRequestDoc()

> > 

> >     Static WordObj As Word.Application

> >     Dim strSaveDir As String

> >     Dim strFileName As String

> >     

> >     strSaveDir = 

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

> > **THIS LINE**  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

> > ---

> > 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&cate

> > go

> > ryid=rn_ebooks

> > 

> > 

> > 

> 

> ---

> 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

> 

> 


  Return to Index