Assigning a textbox string throughout code

S

slickdock

I store all text files that I use for TransferText commands into a folder
called c:\documents and settings\all users\application data\MyTxtFiles. I
want to be able to sometimes change that path, so I put that path in a
textbox control that is bound to my switchboard form, whose source is the
table that contains the myTxtFiles field.

I need to refer to that field [forms!][switchboard]![MyTxtPath] throughout
my code in 4 basic ways:

1. Set wdActiveDoc = wd.Documents.Open( "…MyTxtPath\merge_ad.docâ€â€¦
2. wd.ActiveDocument.SaveAs "…MyTxtPath\merged_ad.doc"
3. If .RecentFiles(y).Path = MyTxtPath Then
If .RecentFiles(y).Name = "merge_ad.doc" Then
.RecentFiles(y).Delete
End If
4. Dim Destination As String
Destination = "MyTxtPath\merge_ad.doc"

Can anyone help me with the proper way to handle this? I don’t want to “hard
code†it by typing the actual path string throughout my code, because that
path may change at times.

Thanks in advance.
 
J

JimBurke via AccessMonster.com

You just need to reference the fully qualified form textbox name, but if
you're concatenating that value with something else it can't appear inside
quote marks - treat it just as you would a VBA variable.

1. Set wdActiveDoc =
wd.Documents.Open( "…" & [forms]![switchboard]![MyTxtPath] & "\
merge_ad.docâ€â€¦
2. wd.ActiveDocument.SaveAs "…" & [forms]![switchboard]![MyTxtPath] & "\
merged_ad.doc"
3. If .RecentFiles(y).Path = [forms]![switchboard]![MyTxtPath] Then
If .RecentFiles(y).Name = "merge_ad.doc" Then
.RecentFiles(y).Delete
End If
4. Dim Destination As String
Destination =[forms]![switchboard]![MyTxtPath] & "\merge_ad.doc"

FYI, you mistakenly had one of the the '!'s inside the brackets in your
example. Be careful when defining that path value. Make sure it is a valid
directory name! If you're allowing it to be changed on the switchboard form,
put in a before update event proc that checks for that.

Based on your example:

Set wdActiveDoc = wd.Documents.Open( "…MyTxtPath\merge_ad.docâ€â€¦

it looks like you sometimes concatenate something in front of that. Is this
field not the full path name? Or does the '...' just represent the 'Forms!...
' part? If it's the full path name then you can ignore the "…" & part in 1.
and 2.

I store all text files that I use for TransferText commands into a folder
called c:\documents and settings\all users\application data\MyTxtFiles. I
want to be able to sometimes change that path, so I put that path in a
textbox control that is bound to my switchboard form, whose source is the
table that contains the myTxtFiles field.

I need to refer to that field [forms!][switchboard]![MyTxtPath] throughout
my code in 4 basic ways:

1. Set wdActiveDoc = wd.Documents.Open( "…MyTxtPath\merge_ad.docâ€â€¦
2. wd.ActiveDocument.SaveAs "…MyTxtPath\merged_ad.doc"
3. If .RecentFiles(y).Path = MyTxtPath Then
If .RecentFiles(y).Name = "merge_ad.doc" Then
.RecentFiles(y).Delete
End If
4. Dim Destination As String
Destination = "MyTxtPath\merge_ad.doc"

Can anyone help me with the proper way to handle this? I don’t want to “hard
code†it by typing the actual path string throughout my code, because that
path may change at times.

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top