A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can we export to a text file to the desktop but using relative paths? [A03]



 
 
Thread Tools Display Modes
  #1  
Old August 18th, 2009, 01:58 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Can we export to a text file to the desktop but using relative paths? [A03]

The best way is to determine the path in your code, and export to that path.

For example, if you've got an environment variable DesktopDir that points to
the user's desktop, you can do something like:

Dim strFile As String

strFile = Environ("DesktopDir") & "\Data.txt"
DoCmd.TransferText acExportDelim, , "MyTable", strFile, True

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"StargateFan" wrote in message
...
Exporting data is pretty standard, I imagine but can A03 be set to
save to a desktop via a relative path so that the file works no matter
what computer we're working on?

i.e., in a scripting language I use, you can use what is called

@DesktopDir

and it will work with relative paths to your current computere's
desktop no matter what the actual path is.

Thanks! D



  #2  
Old August 18th, 2009, 02:08 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Can we export to a text file to the desktop but using relative paths? [A03]

I probably should have mentioned that the problem with trying to use
relative paths is you don't know to what it's going to be relative!

You shouldn't assume anything about the current directory when running an
Access application. There are many different ways of invoking an Access
application (such as using a desktop shortcut, double-clicking on the file,
opening Access then navigating to the file or opening Access and selecting
the file from the MRU list, etc), and each can lead to a different current
directory.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Douglas J. Steele" wrote in message
...
The best way is to determine the path in your code, and export to that
path.

For example, if you've got an environment variable DesktopDir that points
to the user's desktop, you can do something like:

Dim strFile As String

strFile = Environ("DesktopDir") & "\Data.txt"
DoCmd.TransferText acExportDelim, , "MyTable", strFile, True

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"StargateFan" wrote in message
...
Exporting data is pretty standard, I imagine but can A03 be set to
save to a desktop via a relative path so that the file works no matter
what computer we're working on?

i.e., in a scripting language I use, you can use what is called

@DesktopDir

and it will work with relative paths to your current computere's
desktop no matter what the actual path is.

Thanks! D





  #3  
Old August 18th, 2009, 02:21 PM posted to microsoft.public.access.gettingstarted
StargateFan[_2_]
external usenet poster
 
Posts: 36
Default Can we export to a text file to the desktop but using relative paths? [A03]

Exporting data is pretty standard, I imagine but can A03 be set to
save to a desktop via a relative path so that the file works no matter
what computer we're working on?

i.e., in a scripting language I use, you can use what is called

@DesktopDir

and it will work with relative paths to your current computere's
desktop no matter what the actual path is.

Thanks! D

  #4  
Old August 19th, 2009, 12:42 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Can we export to a text file to the desktop but using relative paths? [A03]

"StargateFan" wrote in message
...

I just needed to know how Access deals with relative paths and what
its _own_ variable for the desktop would be. I'm hoping that Access
has something similar to use in a script to save an export of the
data.

So pls, just need that point clarified - does Access handle saving to
a existing relative path variable of its own for the desktop and what
is that variable?


Access does not have its own variables to represent the paths to "special
folders".

You can use API calls to get them, though: see
http://www.mvps.org/access/api/api0054.htm at "The Access Web" for a
complete sample.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



  #5  
Old August 19th, 2009, 01:00 PM posted to microsoft.public.access.gettingstarted
StargateFan[_2_]
external usenet poster
 
Posts: 36
Default Can we export to a text file to the desktop but using relative paths? [A03]

On Tue, 18 Aug 2009 08:58:47 -0400, "Douglas J. Steele"
wrote:

The best way is to determine the path in your code, and export to that path.

For example, if you've got an environment variable DesktopDir that points to
the user's desktop, you can do something like:

Dim strFile As String

strFile = Environ("DesktopDir") & "\Data.txt"
DoCmd.TransferText acExportDelim, , "MyTable", strFile, True


I don't know if I've understood, but I get the impression that the
answer to my question is no (?). I used the term "DesktopDir" merely
as an example of how a scripting language that I have deals with a
relative path to any desktop you're on. When you use this scripting
language, it works without you changing anything even when you switch
host computers. This language has many such relative path variables
to major folders: i.e., @StartupDir, @SystemDir, @UserProfileDir,
etc. So you'd do something like this if this scripting langue were a
database program:

(export command...) = @DesktopDir & "\Export of database file.txt",

and I'd end up with my text file export exactly where I needed it.

I just needed to know how Access deals with relative paths and what
its _own_ variable for the desktop would be. I'm hoping that Access
has something similar to use in a script to save an export of the
data.

So pls, just need that point clarified - does Access handle saving to
a existing relative path variable of its own for the desktop and what
is that variable?

Thanks so much and sorry for any confusion! D

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"StargateFan" wrote in message
.. .
Exporting data is pretty standard, I imagine but can A03 be set to
save to a desktop via a relative path so that the file works no matter
what computer we're working on?

i.e., in a scripting language I use, you can use what is called

@DesktopDir

and it will work with relative paths to your current computere's
desktop no matter what the actual path is.

Thanks! D



  #6  
Old August 20th, 2009, 04:58 AM posted to microsoft.public.access.gettingstarted
StargateFan[_2_]
external usenet poster
 
Posts: 36
Default Can we export to a text file to the desktop but using relative paths? [A03]

On Wed, 19 Aug 2009 07:42:13 -0400, "Douglas J. Steele"
wrote:

"StargateFan" wrote in message
.. .

I just needed to know how Access deals with relative paths and what
its _own_ variable for the desktop would be. I'm hoping that Access
has something similar to use in a script to save an export of the
data.

So pls, just need that point clarified - does Access handle saving to
a existing relative path variable of its own for the desktop and what
is that variable?


Access does not have its own variables to represent the paths to "special
folders".

You can use API calls to get them, though: see
http://www.mvps.org/access/api/api0054.htm at "The Access Web" for a
complete sample.


sigh Darn. Okay. Well, looks like I'll keep the status quo then,
for now.

Thanks. D

  #7  
Old August 20th, 2009, 11:58 AM posted to microsoft.public.access.gettingstarted
Len B[_2_]
external usenet poster
 
Posts: 28
Default Can we export to a text file to the desktop but using relative paths? [A03]

You could look at the possibility of using environment variables as Douglas
suggested in his first reply.

To see what environment variables are available on your system open a
command prompt and type
set enter

Here are some from my system -
COMPUTERNAME=TREES
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Len
SystemDrive=C:
USERPROFILE=C:\Documents and Settings\Len
WINDIR=C:\WINDOWS

You could look at using a combination of Homedrive and Homepath or
Userprofile or some other existing variable. Also, you can create
and use your own custom variables like the ones you are used to from
your scripting language. eg you could create Dsktop=C:\Doc....\Desktop
and use it in Douglas' code.

strFile = Environ("Dsktop") & "\Data.txt"
DoCmd.TransferText acExportDelim, , "MyTable", strFile, True


--
Len
__________________________________________________ ____
remove nothing for valid email address.
"StargateFan" wrote in message
news | On Wed, 19 Aug 2009 07:42:13 -0400, "Douglas J. Steele"
| wrote:
|
| "StargateFan" wrote in message
| .. .
|
| I just needed to know how Access deals with relative paths and what
| its _own_ variable for the desktop would be. I'm hoping that Access
| has something similar to use in a script to save an export of the
| data.
|
| So pls, just need that point clarified - does Access handle saving to
| a existing relative path variable of its own for the desktop and what
| is that variable?
|
| Access does not have its own variables to represent the paths to
"special
| folders".
|
| You can use API calls to get them, though: see
| http://www.mvps.org/access/api/api0054.htm at "The Access Web" for a
| complete sample.
|
| sigh Darn. Okay. Well, looks like I'll keep the status quo then,
| for now.
|
| Thanks. D
|


  #8  
Old August 21st, 2009, 12:59 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Can we export to a text file to the desktop but using relative paths? [A03]

"StargateFan" wrote in message
news
On Wed, 19 Aug 2009 07:42:13 -0400, "Douglas J. Steele"
wrote:

"StargateFan" wrote in message
. ..

I just needed to know how Access deals with relative paths and what
its _own_ variable for the desktop would be. I'm hoping that Access
has something similar to use in a script to save an export of the
data.

So pls, just need that point clarified - does Access handle saving to
a existing relative path variable of its own for the desktop and what
is that variable?


Access does not have its own variables to represent the paths to "special
folders".

You can use API calls to get them, though: see
http://www.mvps.org/access/api/api0054.htm at "The Access Web" for a
complete sample.


sigh Darn. Okay. Well, looks like I'll keep the status quo then,
for now.


It's not that difficult to use the API code.

Copy everything in the shaded area (between Code Start and Code End) and
paste it into a code module (not a class module, nor a module associated
with a form or report). To export to the current user's desktop, use:


Dim strFile As String

strFile = fGetSpecialFolderLocation(CSIDL_DESKTOPDIRECTORY ) & "\Data.txt"
DoCmd.TransferText acExportDelim, , "MyTable", strFile, True


If you want it to be on the desktop for all users of the machine, use
CSIDL_COMMON_DESKTOPDIRECTORY instead of CSIDL_DESKTOPDIRECTORY


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.