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!

Form with Linked Pictures 1

Status
Not open for further replies.

floydpepper

Technical User
Jul 8, 2004
39
US
Ladies and Gents!
Please help. I have a form (Form Main)whose source is a table (Tbl Main). The data base is being established to track personnel info (including .jpg pictures) for HR. I have used the following code (from forums on this site) in the On Current property for the form:

Private Sub Form_Current()
On Error GoTo err_Form_Current

If Not Me!txtPicture = "" Or Not IsNull(Me!txtPicture) Then
Me!Picture.Picture = GetPathPart & Me!txtPicture
Else
Me!Picture.Picture = ""
End If

exit_Form_Current:
Exit Sub

err_Form_Current:
MsgBox Err.Description
Resume exit_Form_Current
End Sub


and this code in the On Open event:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

If IsNull(Me!txtPicture) Or Me!txtPicture = "" Then
' do nothing
Else
Me!Picture.Picture = GetPathPart & Me!txtPicture
End If

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub


with this Function included:

Private Function GetPathPart() As String
' Comments : Returns the path part of a string
' Parameters: strPath - string to parse
' Returns : path part
'
Dim db As DAO.Database
Dim strPath As String
Dim intCounter As Integer

Set db = CurrentDb
strPath = db.Name
db.Close
Set db = Nothing

For intCounter = Len(strPath) To 1 Step -1
If Mid$(strPath, intCounter, 1) = "\" Then
Exit For
End If
Next intCounter

GetPathPart = Left$(strPath, intCounter)

End Function


The form works great. The only difficulty I am having is that the pictures have to be placed on my desktop for the form to function. Is there a way I can designate a specific folder/path for the link so that the users can keep their desk tops clean?

Thank you in advance. The members of this community have been a great help in my slow yet steady development.

FloydP
 
I don't agree to change Application Path to a specific folder. You loose the ability of changing the image and file from folder to folder.
Keep the file in a folder where you feel the images should be and a keep a shortcut of the file on your desktop

________________________________________________________________________
Zameer Abdulla
Visit Me
A person who misses a chance and the monkey who misses its branch can't be saved.
 
ZmrAbdulla,
I'm all about flexibility with this dbase. If I move the image from the desktop into a folder I get the error message:

"Microsoft Access can't open the file'C:\Documents and Settings\my user name\Desktop\my picture name.jpg'."

whenever I open the form or report.

Is there a way to remedy this?

Thanks again.

FP
 
I think you have stored the path into the db earlier. Store only image name in the db and add path on the fly.

________________________________________________________________________
Zameer Abdulla
Visit Me
A person who misses a chance and the monkey who misses its branch can't be saved.
 
Thanks for your patience. I'm an old grunt pushing through the electrons.

When I enter the data for the picture link into the dbase, I only enter "Floyd Pepper.jpg". With this data it pulls the picture from the desktop (how it knows its there I do not know, but would like to). My first follow up question would be:

Should I be entering full path names?

My second:

Is there a simple way to do this? My users will need the easiest entry possible.

Thank you.
 
Where is your db located? Desktop or in a folder?

I can't find anything wrong in this code to get path and file name. That part works fine. The function(Function GetPathPart) gets the db path.
As per this setting you need the db & images to be in the same folder.

You can remove the path and function and place a path directly.
Code:
Private Sub Form_Current()
Dim GetPathPart As String
GetPathPart = "C:\ImagesFolder\"
On Error GoTo err_Form_Current

    If Not Me!txtPicture = "" Or Not IsNull(Me!txtPicture) Then
        Me!Picture.Picture = GetPathPart & Me!txtPicture
    Else
        Me!Picture.Picture = ""
    End If
        
exit_Form_Current:
    Exit Sub
    
err_Form_Current:
    MsgBox Err.Description
    Resume exit_Form_Current
End Sub
And comment out(or erase) the
Code:
Private Function GetPathPart() As String
    ' Comments  : Returns the path part of a string
    ' Parameters: strPath - string to parse
    ' Returns   : path part
    '
    Dim db As DAO.Database
    Dim strPath As String
    Dim intCounter As Integer
    
    Set db = CurrentDb
    strPath = db.Name
    db.Close
    Set db = Nothing
        
    For intCounter = Len(strPath) To 1 Step -1
        If Mid$(strPath, intCounter, 1) = "\" Then
            Exit For
        End If
    Next intCounter
    
    GetPathPart = Left$(strPath, intCounter)

End Function


________________________________________________________________________
Zameer Abdulla
Visit Me
A person who misses a chance and the monkey who misses its branch can't be saved.
 
I have the Dbase on the desktop. What are the steps for designating a locatioon elsewhere for picture retrieval?

Is there an easy way for the user to enter the path to the pic without typing it directly to the Dbase?

Thanks.

FP
 
You may consider the following function:
Code:
Function PickFolder(strStartDir As Variant) As String
    Dim SA As Object, f As Object
    Set SA = CreateObject("Shell.Application")
    Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not f Is Nothing) Then
        PickFolder = f.Items.Item.path
    End If
    Set f = Nothing
    Set SA = Nothing
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Where could I insert this code and how would I use/call this function? Thanks PHV.
 
You may try something like this:
Code:
Dim GetPathPart As String

Private Sub Form_Current()
    If Trim(GetPathPart & "") = "" Then
      GetPathPart = PickFolder("") & "\"
    End If
    If Trim(Me!txtPicture & "") <> "" Then
        Me!Picture.Picture = GetPathPart & Me!txtPicture
    Else
        Me!Picture.Picture = ""
    End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
floydpepper said:
I have the Dbase on the desktop.
This is what I said to keep the db and the images in a folder anywhere except the desktop and keep a shortcut to the db on the desktop.
Worth looking into for more info.



________________________________________________________________________
Zameer Abdulla
Visit Me
A person who misses a chance and the monkey who misses its branch can't be saved.
 
How are ya floydpepper . . . . .

Bear in mind your code is fine (could use a little triming), you just have a location problem.

[blue]CurrentDB.Name[/blue], or as you have it [blue]db.Name[/blue], returns the path to the [blue]current .mdb file[/blue]. In your case the desktop. So if your gonna use [blue]db.Name[/blue] as the [blue]sourcepath[/blue] for your pictures, it should be clear the pictures need to be stored where ever the .mdb is located.

With the above in mind, to get all the pictures off the desktop you have to move the .mdb and picture files to a new location, making a shortcut to the db on the desktop.

Where you relocate is up to you. [purple]Your the designer[/purple] . . . so pick a spot. [blue]This is something I wouldn't leave up to the users[/blue] as you'll wind up with paths all over the place, and if its to be [blue]fully automated[/blue] you'll need a way to tell access the path per user! It will also easier to upload your pictures to a common location.

Having selected your new location and making the proper transfers, use your trimmed code below:
Code:
[blue]Private Sub Form_Current()
   Call PostPic
End Sub

Private Sub Form_Open(Cancel As Integer)
   Call PostPic
   End Sub

Private Function dbPath() As String
   Dim hldPath As String
   
   hldPath = CurrentDb.Name
   dbPath = Left(hldPath, InStrRev(hldPath, "\"))

End Function

Public Sub PostPic()
   Dim Pic As String
   
   If Trim(Me!txtPicture & "") = "" Then
      Me!Picture.Picture = ""
   Else
      Me!Picture.Picture = dbPath & Pic
   End If
   
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
AceMan!

Thanks for the instruction. I moved my dbase to the same folder in which I store my pictures. Then,
I eliminated my existing code and pasted in yours. Now, when I try to open the form I get an error message that reads:

"Microsoft Access can't open the file'C:\Documents and Settings\my user name\Desktop\my folder name'."

When I reference back to the code, the issue seems to be with:

Me!Picture.Picture = dbPath & Pic

Any further help would be greatly appreciated. This is certainly a journey.

Thanks man.
FP
 
floydpepper . . . . .

[purple]My fault![/purple] . . . . replace the PostPic routine with the following:
Code:
[blue]Public Sub PostPic()
   
   If Trim(Me!txtPicture & "") = "" Then
      Me!Picture.Picture = ""
   Else
      Me!Picture.Picture = dbPath & Me!txtPicture
   End If

End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan!

You've earned a combat star.

Now,is there an easy way for the user to enter the picture name (prompt from specified file) or is typing it in the way to go?

Thank you again.

FP
 
floydpepper said:
[blue] . . . is there an easy way for the user to enter the picture name . . .[/blue]
Are you saying . . . . [blue]record by record users have their own pictures they wish to display?[/blue]

I[purple]f no . . . expand on this . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Sorry about that...

Once the user takes the digital picture and saves it to the specified file, should they simply go to the form in the dbase, enter the individual's data and their picture name (.jpg) or is there a way for the form to prompt them (open a separate window displaying the contents of the specified file where the pictures are stored) so that they can select the picture (probably in thumbnail view) and that name will populate the textpicture field on the form?

I know that's a long question, but I have to ask.

Thanks again.

FP
 
floydpepper . . . . .

Where not having a communication problem as much as what I'm trying to drive you to see!
YourPostOrigination said:
[blue]The data base is being established to track personnel info (including .jpg pictures) for HR.[/blue]
If my read is correct, what you need is a way to assign that .jpg to the specific personnel. After all, saving that .jpg to the proper folder only gets you halfway there. Access still doesn't know how to account that .jpg with a specific personnel! . . . IS this correct?

The idea is . . . once a graphic is assigned to a specific personnel, automation can take full control!

[purple]Your Thoughts! . . .[/purple]


Calvin.gif
See Ya! . . . . . .
 
Roger that, AceMan.

You are right on. How can I automate the assigning function (one picture per specific record)?

Thanks again and again.

FP
 
floydpepper . . . . .

I believe your Main form is already setup with personnel first/last name, the Image control and FileName field. All you need is [blue]a way to browse your hard drive[/blue] and update the FileName field as well as the image control.

Have a look at : Using the Common Dialog Control



Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top