exporting to current directory (1 Viewer)

robert909

Registered User.
Local time
Today, 22:01
Joined
May 30, 2003
Messages
12
Hi,

I've got a question about exporting data from an access database. I'm using Access 2000 on windows 2000.

I'm using the following VBA in my database:

Dim name As String
name = "C:\Data\export"
DoCmd.TransferSpreadsheet acExport, , "Q_export",name

So I'm exporting the content of query "Q_export" to the file "C:\Data\export". But I would like to keep the path that I'm exporting the file to variable. I would like to export to the directory where the database is in (so the current directory). I guess that there is some kind of a VBA-code that contains the name of the directory of the current database. So something like:
name = Current Directory & "\export"

Do you know if this is possible with VBA-code?

Thanks again for your help!

Regards,

Robert
 

Tim K.

Registered User.
Local time
Today, 22:01
Joined
Aug 1, 2002
Messages
242
You can try

name = CurrentProject.Path & "\export"

CurrentProject.Path is available for Access 2K or higher.

If you use Access 97, try this instead.

name = fRelativePath & "export"

You'll need the fRelativePath function to help.

Function fRelativePath() As String
Dim strCurName As String
strCurName = CurrentDb.Name
fRelativePath = Left(strCurName, Len(strCurName) - Len(Dir(strCurName)))
End Function
 

Users who are viewing this thread

Top Bottom