Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


How to access file in same path as ACCESS database


How to access file in same path as ACCESS database

Author
Message
victor64
victor64
Forum God
Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)Forum God (5.3K reputation)

Group: Forum Members
Posts: 26, Visits: 28
Hello,

I am trying to view PNG files listed in an ACCESS file, the PNG files are on the same path as the application. Including the following syntax: /intro.png in the
table is not working. Can you please help me with the proper syntax to view the PNG files in the same path as the ACCESS file.

Thanks,

Victor

vb5prgrmr
vb5prgrmr
Forum God
Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)Forum God (40K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Ok, you have the path to your database and just for this example we will say the path is something like...

Dim PathToDb As String

PathToDb = "C:\Program Files\My App\Appinfo\MyDb.mdb"

and now you want to return just the "C:\Program Files\My App\Appinfo\" part. So you need to look at the left and instrrev functions...

Dim PathToDb As String, BasePath As String

PathToDb = "C:\Program Files\My App\Appinfo\MyDb.mdb"

BasePath = Left(PathToDb, InStrRev(PathToDb, "\"))

 

Good Luck

 

Keithuk
Keithuk
Forum God
Forum God (298K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
victor64 (6/2/2009)
Hello,

I am trying to view PNG files listed in an ACCESS file, the PNG files are on the same path as the application. Including the following syntax: /intro.png in the
table is not working. Can you please help me with the proper syntax to view the PNG files in the same path as the ACCESS file.

Well Victor this will depend on a few things. Does this database only store the filename and location of these files? If true then you don't need a database you can load all you pictures from code. If it does then your app will only work on your computer.

Now the App.Path is good enough for this and 90% of the time your app will be running from a folder. If it runs from the root of a drive then that will cause a problem. What I do is use a String variable Ap to find the app location. If you have multiple Forms that need this location then declare it as Public in a Module.  Wink

Option Explicit

Dim Ap As String

Private Sub Form_Load()

If Right(App.Path, 1) = "\" Then
    Ap = App.Path
Else
    Ap = App.Path & "\"
End If

End Sub

Private Sub Command1_Click()

Picture1.Picture = LoadPicture(Ap & "intro.png ")

End Sub

'Or if you want them in a seperate folder then just add the folder name.

Picture1.Picture = LoadPicture(Ap & "foldername\" & "intro.png ")


Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Mark
Mark
Forum God
Forum God (142K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
Now the App.Path is good enough for this and 90% of the time your app will be running from a folder. If it runs from the root of a drive then that will cause a problem. What I do is use a String variable Ap to find the app location. If you have multiple Forms that need this location then declare it as Public in a Module.

This is about the only  place I like using an IIf statement.

Dim AppPath As String

    AppPath = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search