Relative File Path

achalrikhi

New Member
Joined
Nov 20, 2013
Messages
38
Hello friends,

I am working on a project. I have tried few attempts but could not resolve the issue as I am not very good at vba as I am just a beginner. I am trying a DoCmd statement. Now the prblem is that I am working on three machines, office, home and laptop. all of them are having different file path for my project and the file I am trying to import through docmd statement.

My question is " Can we have a relative OR global file path for the file I want to import, so that the docmd statement will work on every computer. The statement I am using is this :

DoCmd.TransferText acImportDelim, "fo Import Specification", "TblFutures", FileName:="C:\Users\welcome\Desktop\Cash.csv", HasFieldNames:=True

Is it possible to write a file path which is global or relative or at least good enough to work on every machine ?

Please advise.

Regards

Achal
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Is the database loaded in the same path as the CSV file?
 
Upvote 0
Is the database loaded in the same path as the CSV file?

Yes. It is a very small project so I have kept it on the desktop it self for the sake of convenience. And the file which is to be imported is also on the desktop.

Regards

Achal
 
Upvote 0
You can use this then. Perhaps check out the path on the other computers first to make sure it is correct.

FileName:=CurrentProject.Path & "\Cash.csv", HasFieldNames:=True
 
Upvote 0
You can use this then. Perhaps check out the path on the other computers first to make sure it is correct.

Dear Trevor G,

This works fine but there are two things,

User will not be able to save the name as per their wish and secondly the file will be saved where the project is lying.

I just found out a way to this : FileDialog box for saving. This will not only enable the user to give a name for the file but the user will also be able to choose the path where he/she wants it to save. The code and the issue is :

Private Sub Command28_Click()


Dim intChoice As Integer
Dim strPath As String


'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogSaveAs).Show
'determine what choice the user made


If intChoice <> 0 Then
'get the file path selected by the user
strPath = _
Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)
'displays the result in a message box
Call MsgBox(strPath, vbInformation, "Save Path")


DoCmd.TransferText acExportDelim, "fo Export Specification", "Fo", strPath, True
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM TblFutures;"
DoCmd.SetWarnings True
End If


End Sub

Now the issue is, when I run this code it gives me the error :

Run-time error '3027' :

Can not update. Database or object is read only.

Now please suggest a solution to deal with this.

Regards

Achal

 
Upvote 0

Forum statistics

Threads
1,221,854
Messages
6,162,448
Members
451,765
Latest member
craigvan888

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top