Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access Database working differently on two computers

Hi

In Access VBA I use the following code to get the path  that the project is in. It works on my client's computer but not on mine.
Why might this happen?

Function Get_DropBox_on_Desktop()

     Dim oDataBasePath As String
     oDataBasePath = CurrentProject.Path
     Dim arrSplit As Variant
     arrSplit = Split(oDataBasePath, "\")
     Dim oDatabaseFileName As String
     oDatabaseFileName = arrSplit(UBound(arrSplit))
     Get_DropBox_on_Desktop = Replace(oDataBasePath, oDatabaseFileName, "")

    
End Function

Open in new window

Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

the above gives the parent directory.

What is u need and what error are you getting? Might not be working as expected if the project path is different on each pc.
Is the database on your computer saved in the "C" folder (or the root of a mapped drive)?

I suspect that the array populated by arrSplit = Split(oDataBasePath, "\") and the Replace function (which pulls the file name of the database) is expecting at least two forward slashes in the path.  If the database is stored in a folder whose path has only one (C:\DatabaseName.accdb) the code can't handle it.

This function will give you the path to the folder in which the database file is saved:
Public Function DatabaseLocation()
     Dim strDBPath As String, strDBName As String
     strDBPath = CurrentProject.Path
     strDBName = CurrentProject.Name
     DatabaseLocation = Replace(strDBPath, strDBName, "")
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Get_DropBox_on_Desktop

That may be your issue. Never run an Access application directly off a DropBox or OneDrive folder.
Avatar of Murray Brown

ASKER

Thanks