VBA code to locate current directory of MDB file and...

T

tasuki

Hi,

I'm not very good with VBA at all. Can someone help me
with this problem. I have a folder like this:

Database [Folder]
->DB.MDB
->Pictures [Folder]
--->PIC1.JPG
--->PIC2.JPG

The thing is the Database folder gets moved around a lot
for viewing and editing purposes. Right now the code
looks something like this to link images to the forms.

**code begin**
Private Sub Form_Current()
Me!Image44.Picture = "M:\Database\Pic\blank.jpg"
If Me![PicID] <> 0 Then
Me!Image44.Picture = "M:\Database\Pic\" & Me!
[PicID]
End If
End Sub
**code end**

[PicID] is the name of the file, Image44 is the control
box where the image goes. The problem is, I want the VB
code to automatically detect its current location (if
possible) and update it accordingly. Right now the
location is static... but I want it to change whenever it
gets moved.

IE. Moving to C:\Desktop\ --> changes link to
C:\Desktop\Database\Pic\

Can this be done? And if so, can anyone please help me?

Thanks!

-T
 
R

Rick Brandt

tasuki said:
Hi,

I'm not very good with VBA at all. Can someone help me
with this problem. I have a folder like this:

Database [Folder]
->DB.MDB
->Pictures [Folder]
--->PIC1.JPG
--->PIC2.JPG

The thing is the Database folder gets moved around a lot
for viewing and editing purposes. Right now the code
looks something like this to link images to the forms.

**code begin**
Private Sub Form_Current()
Me!Image44.Picture = "M:\Database\Pic\blank.jpg"
If Me![PicID] <> 0 Then
Me!Image44.Picture = "M:\Database\Pic\" & Me!
[PicID]
End If
End Sub
**code end**

[PicID] is the name of the file, Image44 is the control
box where the image goes. The problem is, I want the VB
code to automatically detect its current location (if
possible) and update it accordingly. Right now the
location is static... but I want it to change whenever it
gets moved.

IE. Moving to C:\Desktop\ --> changes link to
C:\Desktop\Database\Pic\

Can this be done? And if so, can anyone please help me?

The following returns the folder path of the currently running Access file.

Left(CurrentDB.Name, Len(CurrentDB.Name)-Len(Dir(CurrentDB.Name))-1)
 
T

tasuki

Thanks Rick.

Code works perfectly. 4 ****. :)

-T
-----Original Message-----
tasuki said:
Hi,

I'm not very good with VBA at all. Can someone help me
with this problem. I have a folder like this:

Database [Folder]
->DB.MDB
->Pictures [Folder]
--->PIC1.JPG
--->PIC2.JPG

The thing is the Database folder gets moved around a lot
for viewing and editing purposes. Right now the code
looks something like this to link images to the forms.

**code begin**
Private Sub Form_Current()
Me!Image44.Picture = "M:\Database\Pic\blank.jpg"
If Me![PicID] <> 0 Then
Me!Image44.Picture = "M:\Database\Pic\" & Me!
[PicID]
End If
End Sub
**code end**

[PicID] is the name of the file, Image44 is the control
box where the image goes. The problem is, I want the VB
code to automatically detect its current location (if
possible) and update it accordingly. Right now the
location is static... but I want it to change whenever it
gets moved.

IE. Moving to C:\Desktop\ --> changes link to
C:\Desktop\Database\Pic\

Can this be done? And if so, can anyone please help me?

The following returns the folder path of the currently running Access file.

Left(CurrentDB.Name, Len(CurrentDB.Name)-Len(Dir (CurrentDB.Name))-1)


.
 
C

Chris Nebinger

If using Access 2000 or above, CurrentProject.Path works
too.


Chris Nebinger

-----Original Message-----
Thanks Rick.

Code works perfectly. 4 ****. :)

-T
-----Original Message-----
tasuki said:
Hi,

I'm not very good with VBA at all. Can someone help me
with this problem. I have a folder like this:

Database [Folder]
->DB.MDB
->Pictures [Folder]
--->PIC1.JPG
--->PIC2.JPG

The thing is the Database folder gets moved around a lot
for viewing and editing purposes. Right now the code
looks something like this to link images to the forms.

**code begin**
Private Sub Form_Current()
Me!Image44.Picture = "M:\Database\Pic\blank.jpg"
If Me![PicID] <> 0 Then
Me!Image44.Picture = "M:\Database\Pic\" & Me!
[PicID]
End If
End Sub
**code end**

[PicID] is the name of the file, Image44 is the control
box where the image goes. The problem is, I want the VB
code to automatically detect its current location (if
possible) and update it accordingly. Right now the
location is static... but I want it to change whenever it
gets moved.

IE. Moving to C:\Desktop\ --> changes link to
C:\Desktop\Database\Pic\

Can this be done? And if so, can anyone please help
me?

The following returns the folder path of the currently running Access file.

Left(CurrentDB.Name, Len(CurrentDB.Name)-Len(Dir (CurrentDB.Name))-1)


.
.
 
T

taasukii

Thanks, that's good to know. ;) Well, much simpler... I'll try that

Thank you both

-T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top