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!

Images in Forms

Status
Not open for further replies.

Gaylord

Technical User
Sep 26, 2002
49
DE
Hi,

I am new to creating forms for Access, but have worked through (well guessed) large parts of how to link fields, etc and everything looks nice.... but now I have reached the image column.

I would like to be able to have, say, a button called "show image", then when pressed will open a viewer program and display the image.

Currently I have converted the image paths into hyperlinks as this was the only way I could get them to appear (by fiddling with file names).

Any help on this would be very gratefully recieved as I am currently pulling whats left of my hair out.

Best regards

Jamie
 
Hi Jamie,

What I did was enter the file paths as text in a table and created a button that would look for the filepath that was related to the Donor's ID number. If found, it opens it in a the document viewer. I am in the process of adding a form where they can enter the file name and I will add the file path automatically.

Here is the code:

Private Sub cmdGetImage_Click()
'procedure name, control name (command button), Donor ID Num
CreateHyperlink Me!cmdGetImage, Me!donor_donorID
End Sub

Sub CreateHyperlink(ctlSelected As Control, intDonor As Integer)
Dim hlk As Hyperlink
Dim Msg, Style, Title, MyString, Response As String 'Variable used for MSGBOX
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strAddress As String

Msg = "There is no image for this file." & Chr(13) & _
"Would you like to add an image?" ' Define message.
Style = vbYesNo + vbInformation + vbDefaultButton2 ' Define buttons.
Title = "Attention" ' Define title.



Set cnn = CurrentProject.Connection

rs.Open "Images", cnn, adOpenDynamic, adLockOptimistic, adCmdTable

Do While Not rs.EOF
If rs!donor_donorID = intDonor Then
strAddress = rs!file
Select Case ctlSelected.ControlType
Case acLabel, acImage, acCommandButton
Set hlk = ctlSelected.Hyperlink
With hlk
If Not IsMissing(strAddress) Then
.Address = strAddress
Else
.Address = ""
End If
.Follow
.Address = ""
GoTo fin
End With
Case Else
MsgBox "The control '" & ctlSelected.Name _
& "' does not support hyperlinks."
End Select
Else
GoTo nextrec
End If

nextrec:
rs.MoveNext
Loop

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then ' User chose Yes
'Open New Form for adding file name
docmd.OpenForm addPath, acNormal
Else ' User chose No.
Exit Sub
End If


fin:

End Sub

I hope this helps you. If you want to a little more information, use the MS Help under the code window and type in Hyperlink.

Good Luck!

MuffinGal


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top