Database in Access address route to export queries to excel

0

I have a Database in MS Access 2016 with a Path to export Queries to Excel. However, sometimes I must work on other computers, so I need to define a permanent Route for my Database.

In the lines of code below, the first route works well, but the second one shows

  

ERROR 3044 "... \ CurrentProject.Path ..." is not a valid path.

On the web I have not found how to write the second code correctly. I appreciate your help.

First Code Path works fine.

sExcelWB = "D:\testing\" & Replace(Me.txttask_from, "/", "_") & " - " & Replace(Me.txttask_to, "/", "_") & " - " & Replace(Me.txttask_plot, "/", "_") & "_qry_task.xls"

Second Code Path shows Error 3044

sExcelWB = "CurrentProject.Path\" & Replace(Me.txttask_from, "/", "_") & " - " & Replace(Me.txttask_to, "/", "_") & " - " & Replace(Me.txttask_plot, "/", "_") & "_qry_task.xls"
    
asked by sabael 11.08.2018 в 16:13
source

3 answers

1

If you talk about the location path of the files, you should establish it relatively.

Examples of location:

Absolute: C: \ User \ Desktop \ program_folder \ file_folder \ file.txt

Relative: file_file \ file.txt

These two will work the same but if you change the program folder to another pc, only the relative will work.

I explain the example, in the absolute location the hard disk name appears and you are a user, etc. Things that usually change between each pc so the absolute location or full location will not work on another pc. Instead, the relative position begins to search from the place where the program is located so if the file is in a folder inside the main solution ('folder') of your program you just have to put the name of the folder that contains the file and then the name of the file ('file_folder \ file.txt').

If the file folder is not within the solution of the program you can use the relative location with the colon rule:

Example of a file inside a folder that is on the desktop like the program, as in this case the folder of the file is not inside the program, we can not access it just by entering the name but we must to exit the program folder and then enter the file folder.

Example:

Complete locations:

Program: c: \ user \ Desktop \ program_folder \ program.exe

Reference file: c: \ Desktop \ folder_file \ file.txt

These are the locations that would not work on another PC.

Relative locations: To refer to the reference file, you should only do the following: .. \ file_folder \ file.txt

If you notice the two points return to the container or parent folder is the desktop where the program folder and file folder is located so that with two points at the beginning of our chain we indicate that you return back to the parent folder and then enter the file folder and find the file.txt.

I hope this documentation will help you. File path

Simple Explanation: Example: You have your program on the desktop inside a folder called program_folder , inside which is your program program.exe .

You also have the excel files in a folder that is on the desktop with the name of carpeta_excel inside it you have your excel file called excel.xlsx . . p>

If you want your program to work on any computer when you put the address of your file in programming, you use the relative form. In this case it would be:

..\carpeta_excel\excel.xls

And your program will work with that route on any computer that uses the program.

Why is it in the other section of the answer.

    
answered by 11.08.2018 в 21:14
0

on the desktop the BDR folder and I wrote the following code with the relative path:

sExcelWB = "C:\CurrentProject.Path\BDR\" & Replace(Me.txttask_from, "/", "_") & " - " & Replace(Me.txttask_to, "/", "_") & " - " & Replace(Me.txttask_plot, "/", "_") & "_qry_task.xls"

However, this time it shows Error 3041 in the line of code:

Set wb = xl.Workbooks.Open(sExcelWB)

Despite many attempts, I have not been able to correct this error, so I appreciate the guidance that you can suggest.

    
answered by 12.08.2018 в 00:59
0

Following what I understood about the points (..) for the Relative Route I tried-unsuccessfully-the following combinations:

"C:\..\BDR\" &
"C:..\BDR\" &
"C:\Escritorio..\BDR\" &
"C:\Escritorio\..\BDR\" &

So, every time I use another computer, I'm forced to open the code to change the route. For the above, I appreciate your help to correct my error in the Relative Route.

    
answered by 12.08.2018 в 03:16