0

I've got a form that can be loaded from USB stick, from my home computer, or from work computers. The form executable is always stored in "some path\National Payroll\Build* and references a database in "some path\National Payroll".

The some path part changes, but the database is always in the parent directory. I've tried other advice to get the form's path, but I can only seem to get the path of the Local AppData folder where the form runs from when it is open, not the path of the form's executable. How do I get that?

dbc
  • 104,963
  • 20
  • 228
  • 340
dya
  • 190
  • 1
  • 13

1 Answers1

0
Application.StartupPath

And, eventually Application.StartupPath.Parent

EDIT: TEST REPORT

Make a new project. Add a form with two TextBoxes named StartupPath and ExecutablePath. In the Form's Load event put the following code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    StartupPath.Text = Application.StartupPath
    ExecutablePath.Text = Application.ExecutablePath
End Sub

Compile and deploy the executable on a USB flash drive (or wherever you want) and double click. This output will be produced: enter image description here

theBugger
  • 441
  • 3
  • 14
  • No luck, this is what I'm getting from Application.StartupPath: C:\Users\\AppData\Local\Apps\2.0\HH0OX23A.ZJJ\O46NDK9E.J0N\payr..tion_0000000000000000_0001.0001_8f5e8a88557cdbef – dya Oct 10 '16 at 07:31
  • Try with Applocation.ExecutablePath – theBugger Oct 10 '16 at 10:07
  • Nope, same. I was down this route with another person on this same thread, but he deleted his comments, unfortunately. – dya Oct 10 '16 at 10:38
  • Please see the edit. I added some test code, give it a try – theBugger Oct 10 '16 at 17:39