Murray Brown
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?
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
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:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Get_DropBox_on_Desktop
That may be your issue. Never run an Access application directly off a DropBox or OneDrive folder.
ASKER
Thanks
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.