View Full Version : Relative Path problem


Nogi
03-01-2005, 04:58 AM
Hi everybody. I'm hoping somebody could help me out with this issue, cause i've searched all over the internet but cannot seem te find any solution.

Idea:

1. I have an excelsheet, containing some information that needs to be transfered into an access database.
2. In order to do that, i've created a macro in an access database
3. The macro in the access-database, is launched by a press on a button in the excelsheet that contains a certain vba-code.

Problem:

The path of the database in the vba-code may not be an absolute path. If i use an absolute path, the code works. When i try to make it relative, it fails with a "Run-time Error 242: Object Required".
Does anyone have an idea how to solve this? Or what i'm doing wrong?

This is the working code with absolute path:

Sub GetAccess()
Application.StatusBar = "Working in MS Access"
Dim MyAccess As Object
Set MyAccess = CreateObject("Access.Application")
MyAccess.OpenCurrentDatabase "C:\Blue Books\start project\database.mdb"
MyAccess.DoCmd.RunMacro "Run"
MyAccess.Quit
End Sub

Now this is what i've changed (with the error as result):

MyAccess.OpenCurrentDatabase "C:\Blue Books\start project\database.mdb"
i changed into:
MyAccess.OpenCurrentDatabase (App.Path & "\database.mdb")

Is there anyone that has an idea of what went wrong? Or how i can make this work?

Thanks in advance for your helps

Nogi
03-01-2005, 11:47 PM
I found a solution to the problem already. You may consider this topic closed

modest
03-02-2005, 07:35 AM
Generally it's a good idea to post your solution, so you don't keep anyone else who needs it guessing. Or... delete your posts so no one has to see it.

I really don't see your need for this, but I would first try three things (I don't work with App.Path... so I dont know what it would return):

1a) MyAccess.OpenCurrentDatabase (App.Path & "\database.mdb")
1b) MyAccess.OpenCurrentDatabase (App.Path & "database.mdb")
2a) MyAccess.OpenCurrentDatabase App.Path & "\database.mdb"
2b) MyAccess.OpenCurrentDatabase App.Path & "database.mdb"

if that doesn't work... just use:
3) MyAccess.OpenCurrentDatabase CurrentDb.Name

Treason
05-16-2005, 06:09 AM
The only problem is CurrentDB.Name returns the path and the DB name... App.Path in vb returns the path without the exe name, So to workaround this try:


Public Function AppPath()
Dim WholePath As String
Dim IntX As Integer
Dim IntY As Integer
WholePath = CurrentDb.Name
For IntX = 1 To Len(WholePath)
If InStr(IntX, WholePath, "\") <> 0 Then
IntY = InStr(IntX, WholePath, "\")
End If
Next IntX
AppPath = Mid(WholePath, 1, IntY)
End Function


Calling AppPath would return just the Current path