Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an exe file with a relative path

Status
Not open for further replies.

TomBijl

Technical User
Apr 13, 2002
8
NL
Hello,

I've been trying to find the solution in the forums, but I can't seem to get the right one. What I want to do is to start an .exe file from a command button. This on its own is not that difficult but I wish to be able to use the relative path it is in depending on where the db is installed.


Dim stAppName As String

stAppName = "file.exe"
Call Shell(stAppName, 1)

The stAppName does work when you use the full path (e.g. c:\temp\file.exe), but not with just the file name.

Is there a way to start an .exe with a relative path? Or read the path where the db(it's in the same spot as the .exe) is in and then use that somehow in the stAppName command?

Thanks
Tom
 
If you can't use "..\brotherfolder\filename.exe" then run a batch file in the current directory that uses a relative path. right?

LB
 
I'll try that.

Not sure how it would work.

Thanks
 
That still don't work. I still have to refer to the bat file using a fixed location, so that doesn't help me.

Well thanks for the advice :) I'll keep on trying.

Tom
 
Once I wrote a next function and it works in NT-environment and I suppose, that it should work also in other Microsoft environments.
Result of this function is current database path.

Hopefully it helps!

Function FindDatabasePath() As String
'function returns absolute path of current database
Dim dbnimi As String
Dim algnimi As String
Dim slash, count As Integer
Dim db As Database

Set db = CurrentDb()

dbnimi = db.Name
count = 0
Do While InStr(dbnimi, &quot;\&quot;) <> 0
slash = InStr(dbnimi, &quot;\&quot;)
count = count + slash
dbnimi = Mid$(dbnimi, slash + 1, 999)
Loop
FindDatabasePath = Mid$(db.Name, 1, count)
End Function

 
I've an even easier way to get the current db loactaion:

Function GetDBLocation() As String
dim db as Database
set db=currentdb

GetDBLocation=left(db.name,len(db.name)-len(dir(db.name)))

end function

B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Thanks,

I go try them both. See what works best :)

Tom
 
Thanks guys.

I go try them instantly!

Tom
 
They worked. I used the short version (sorry oharab). Using a new variable I made the entire path command line for the .exe and used that variable in the stappname = variable and that does the trick.

Thanks again.
Tom
 
I going to use also short version - it is really ELEGANT. My solution is written years ago, when I started VBA programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top