Solved

Using CurrentProject.path

Posted on 2006-07-13
27
276 Views
Last Modified: 2011-10-03
I have a database that I use to make Accountability Cards for evacuation purposes.  These cards have the photos of the employees on them.  I am in the process of incorporating the Accountability Cards into our Employee Database...seems silly to have two different databases to hold information about our employees and my coworkers think it would be a great idea to be able to pull up someones record in the Employee Database and see their picture (Will have to figure out how to block mine haha).

I saw that you can use CurrentProject.path to get the path of the database.  If I stored the pictures in the same folder as the database (in a folder called Pictures), could I use CurrentProject.path to help me show the pictures of the employees?  One of the reasons I want to be able to do this is if for some reason they need to move our folder on the network the drive may change names (from rdc1 to HarryTheHamster) and I don't want to have to go in and find all the places in my code where I use rdc1 (not that there are very many, but if I win the lottery I won't be here to fix their broken picture links).

Is using CurrentProject.path for this possible (and not really complicated)?

Thanks!
Lena
0
Comment
Question by:LenaWood
  • 13
  • 6
  • 5
  • +1
27 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17103403
Where are you planning on holding the database, is it shared on the network?
Ideally u want the photo's held on a network drive that is regularly backed up

I dont belive it matters too much

Even if you store the path of images in a config table, u will be alright

Thats the best thing to do I reckon. Store the path (can be currentproject.path or some predefined network dir)
then u can use this to build your images

Advantage I guess of holding in same place as database is if u move database directory then everything goes.
But if users know location of database, would it not be advisable to put into a place where your users cant hack about?
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17103713
Where this database resides is on a network drive that is backed up every night (at least the files that changed during the day) and completely backed up once a week.

The users of the database will have a front end stored on their desktops and won't have the drive actually mapped to their computers - I know that doesn't solve issues with people messing with the pictures, but most people out here don't know how to map a drive to be able to mess with the pictures.

So I could store something like Photos\LenaWood.jpg in a field in my table, and when I tell the picture box on my form (OLE object?) where to look, I could say Currentproject.path & "\" & me.pictureplace, right?  Of course my next question will be how to store just the Photos\LenaWood.jpg, but I will figure that out down the road (if this is doable).

Lena
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17103810
Yes thats okay then

Use a image control to load your pictures. Very easy

just do

imgCtrl.Picture = currentproject.path & sImageFilePath


Nothing wrong with what u do, but if I did this, I would still store a path in a table and make use of that.
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17103878
If I store the path in the table and the database gets moved to a different sever then all my paths are wrong...no?  How would I automatically fix the path names?  I need to do something that won't need to be fixed by ME if IT chooses to switch the servers....I plan on winning the lottery and going on a very very long vacation :-)

Lena
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17103901
yes, thats true. Thats why its a config table, u simply change the path in that table

Your approach is easier in terms of maintenance.

I guess photo's can be considered data and therefore being placed with a backend database is fine.

I would recommend you make the photo's directory read only for all users, except admin

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17103905
I see u still remember good old Harry the Hampster!
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17104028
So the path (the first part of it anyway) is stored in a single field in a table...yes?  So how do I link a single photo to each person.  OK...maybe today isn't a good day for questions...I am catching my daughters "blonde" attitude.

Lena
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17104229
Is this a FE split application?
Or does the "FE" actually sit on the server - shared by all?

I'm just wondering of how much use currentproject.path will be - you don't want images stored on local pc's surely. :-S
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17104291
It is split and each person has their own personal front end.  The BE is stored on the network drive.

0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17104378
As it should be - cool.
And you'll want to store these images with the data files on the server yeah.

But that means currentproject.path won't be of much help in that respect.
You'll have to examine the table link yeah?
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17104410
Yes, the photos will be stored in a subfolder in the folder with the mdb files.
Yes...I didn't even think about the table link...well phoey!
0
 
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 150 total points
ID: 17104463
If this is all standard Access to Jet data then just

mid(CurrentDb.TableDefs("LinkedTableName").Connect, 11)

should get you the BE file path.
To get the folder you could have a wee function

Function BEPath(strTableName As String) As String

BEPath = Mid(CurrentDb.TableDefs(strTableName).Connect, 11)
BEPath = Left(BEPath, InStrRev(BEPath, "\"))

End Function
0
 
LVL 39

Assisted Solution

by:stevbe
stevbe earned 100 total points
ID: 17107722
someone for sure is going to want to move the pictures to another location for another reason and you won't want to give the user's of the other location visibility into your network datbase path, play along nicely with rocki and go with a configuration table.

I typically create private module vars and public functions to return these values as needed ...

in a standard module ...
Private mstrPicPath As String

Public Function PicPath() As String
    'only retrieve pic path if we have not already done so ...
    If Len(mstrPicPath) = 0 Then
        mstrPicPath = DLookup("Value", "ztblConfig", "Setting='PicPath'"
    End If
    PicPath = mstrPicPath
End Function

now in the form you want to display the pics ...

Private Sub Form_Current()

    'make sure a picture file has been stored
    If Len(Me.txtPicFile.Value & vbNullString) = 0 Then
        Me.imgEmp.Picture = PicPath & "NoPicAvailable.jpg"

        'add error to your log to notify admin that no pic for this emp exists yet
        ' exercise left to Lena
        Exit Sub
    End If
 
    'make sure you can find the picture
    If Len(Dir(PicPath & Me.txtPicFile.Value)) = 0 Then
        Me.imgEmp.Picture = PicPath & "PicNotFound.jpg"

        'add error to your log to notify admin that picture is mising but db thinks there is one
        ' exercise left to Lena

        Exit Sub
    End If

    'hey ... there really is a picture
    Me.imgEmp.Picture = PicPath & Me.txtPicFile.Value

End Sub

Steve
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 39

Expert Comment

by:stevbe
ID: 17107738
ok ... so how do you get the name of the picture file into your database ...

getb the common file dialog api code if you do not already have it ... (http://www.mvps.org/access/api/api0001.htm)

and add a builder button on your employee administration form to navigate to your picture folder and select the appropriate picture.

Steve
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17122659
Leigh,

The code you gave does show the path to the backend and just the path to the folder itself.  I am sure this will be useful when I figure out what I am going to do with this.

Steve,

I have something similar to the link that you gave me - I was going to use it for making my mom a database for her Tole Books.  She wanted to be able to show the cover of the book in the database (easier to show the insurance what books she had that way).  Anyway, the code that I am using shows me the complete path to the picture.

CODE:

Private Sub GetPic_Click()

Dim strFilter As String
Dim strInputFileName As String

'create the filter that displays in the "File Type" drop down at the bottom of the File Dialog box
'I made it jpg based on earlier discussions ... you can make it whatever you want.

strFilter = ahtAddFilterItem(strFilter, "Picture Files (*.JPG)", "*.JPG")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strFilter = ahtAddFilterItem(strFilter, "Picture Files (*.BMP)", "*.BMP")
strFilter = ahtAddFilterItem(strFilter, "Picture Files (*.gif)", "*.GIF")

'open the file dialog box and return path to the selected file
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select a picture file...", _
Flags:=ahtOFN_HIDEREADONLY)

'make sure a file was selected
If Len(strInputFileName) > 0 Then
'write the value to the textbox that is bound to your PicPath field
Me.PicPath.Value = strInputFileName

'display the selected picture
Me.imgPic.Picture = Me.PicPath.Value
End If

End Sub

Gives me:  N:\ToleBook\ToleBooks\Gourd Fun.gif

My question I guess is how would I get it to just show me Gourd Fun.gif?

I am not sure how much I will understand today...spent all day out in the heat yesterday (at an estate auction) and didn't get home until 1am this morning....I am functioning on luck this morning.

Lena
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17122797
I just realized that no matter how much I am trying to make it so that if something gets moved it won't help alot.  I have a Auto-Updater in use (I update the front end of the database and when each person starts their own database front end it checks to see if they have the newest version) and you have to point it to the front end (Master copy) on the server...if it gets moved the database just won't startup.

Oh well....I still want to make this other part work.  The more I have set up to fix itself, the less someone else will have to figure out how to do :-)

Lena
0
 
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 150 total points
ID: 17122869
From strInputFileName you'd just take

Mid(strInputFileName, InstrRev(strInputFileName,"\")+1)

to get the file name.
You'd then copy that to your own folder location (be it named in a settings table - or relative to your BE folder placement).
Once there - it's a relative path and you'll always know where it is (either based on a new settings value or a new BE location).

0
 
LVL 10

Author Comment

by:LenaWood
ID: 17124399
Thank you, I will try this out and let you know how it goes.

Lena
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17124439
OK...silly question.  Should the config table actually be in the backend?  Using my tired logic, I would say no...but then again I am tired.

Lena
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17124498
No is right :-)

(Although - that could depend on the config tables you have - I usually have a local one and a systemwide one).
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17124771
Hey Lena, I see your going for the config table approach

Good choice

I guess Leigh is better at explaining that approach than I was!

0
 
LVL 10

Author Comment

by:LenaWood
ID: 17125302
No Rocki - you and Harry the Hamster are quite the team :-)  I understood what you thought I should do, just wasn't 100% sure I understood how to go about it is all.  My head just hasn't been in the game lately - but don't give up on me.

Rocki uses the gentle approach....Leigh just smacks me over the head...each approach works depending on the day!

Honestly, I couldn't and wouldn't be here at my job doing what I do today without the 3 of you (Rocki, Leigh and Harry) among many others.

THANKS!
Lena
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17125327
Thanks!

I thought my kids were bad, damn, Im watching this program called Driving Mum and Dad

3 yr olds swearing and hitting their parents, damn
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17125407
Makes you wonder why the parents didn't put a stop to it the first time it happened.  My kids would NEVER do anything like that...they may want too, but don't.  (I am glad they don't, as they are both able to kick my butt now - getting old sucks!).

Thanks again Rocki....you will be awarded as you derserve, not only with EE points, but also with the gratitude of many.

Lena
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17129289
For your picture path I would put that in a BE config table so you can cghnage it on the fly without distributing a new version of the FE. That is why my "PicPath" function stores the results in a var, you only have to make a hit to the BE one time per session.

Steve
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17129409
Thank you Steve for the information.  My goal for today is to make this work.  I shall return with more questions if I have them.

Lena
0
 
LVL 10

Author Comment

by:LenaWood
ID: 17131407
Thank you Rocki, Steve and Leigh....you have all helped me learn alot with this question.

Until the next question.....:-)

Lena
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now