open folder from hyperlink

Cereldine

Registered User.
Local time
Today, 00:31
Joined
Aug 4, 2005
Messages
71
hi, a desirable feature of a databse im building would be for the user to upload a jpeg image to the database. Ideaaly for simplicity it would be better to just save the image in a specific windows folder and then save its filepath as a hyperlink in a related table. Is it possible for access to achieve this? This is the sort of way i have done it with asp.net web applications but don't know whether the method transfers over to access. Any comments or advice grateful.
 
You need to create an unbound ImageFrame on your form and thenusing the following code, link it to an image in (say) the c:\temp directory. In my database, I name the picture as an integer that matches the record number for the client name.

This code 9with a few variations for yourself) should do it.

On the form use

Private Sub Form_Current()
'
On Error GoTo Err_NewRecord
'
intPath = CustomerID.Value
CallDisplayImage
If strResult = "" Then
txtImageNote.Visible = False
Else
txtImageNote.Visible = True
End If
'

Exit_NewRecord:

If IsNull(Me![CustomerID]) Then
DoCmd.GoToControl "CustomerFirstName"
End If

Exit Sub
'
Err_NewRecord:
Select Case Err.Number
'
Case 94
ImageFrame.Visible = False
Resume Exit_NewRecord
'
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_NewRecord
End Select

End Sub


Then create a new Module for the calling code;

Option Compare Database
Option Explicit

Public strPath As Variant
Public intPath As Integer
Public strResult As String


Public Function DisplayImage(ctlImageControl As Control, strImagepath As Variant) As String
'
On Error GoTo Err_DisplayImage
'
'PATH to DEFAULT FOLDER
'======================
strPath = "c:\temp\" & intPath & ".jpg"
'
strImagepath = strPath
strResult = ""
'
With ctlImageControl

.Visible = True
.Picture = strImagepath

End With

Exit_DisplayImage:
DisplayImage = strResult
Exit Function

Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "No image specified"
Resume Exit_DisplayImage:
'
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function


Hope this works - please let me know how you get on.
 
I have tried fitting your code into my application, i cannot compile the code though. I get the error with the line
CallDisplayImage
the error states function not defined, if i put a space after call then the error changes to arguement not optional, guess this is because it expects ctrlimagecontrol as a arguement etc)
any ideas? thanks for posting as well
 
ted.martin said:
Public Function DisplayImage(ctlImageControl As Control, strImagepath As Variant) As String
'
On Error GoTo Err_DisplayImage
'
'PATH to DEFAULT FOLDER
'======================
strPath = "c:\temp\" & intPath & ".jpg"
'
strImagepath = strPath
strResult = ""
'
With ctlImageControl

.Visible = True
.Picture = strImagepath

End With

Exit_DisplayImage:
DisplayImage = strResult
Exit Function

Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "No image specified"
Resume Exit_DisplayImage:
'
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function


Hope this works - please let me know how you get on.

Just as a question, why do you have any arguments to this? or at least, why have the strImagePath argument? the first thing you do is over ride whatever is put in it.
 
Call Display Image needs to be in the Modules part of the programme and declared as Public just as I have written it.

The code does work so just check you have set the image frame up correctly.

The other thing is if you are using the c:\temp path, you will have set create this folder as c:\temp is not a Windows XP standard. I use c:\themp because Documents and Seeting, My Documents, name etc is a bit too laborious to type.
 
Last edited:
What do you mean by the image frame & how do u set one up? Do you mean a image control or an unbound object? I take it you have called it ctlImageControl as well or am i looking at this wrongly?
 
I wasnt questioning that it works, was just wondering why you have an argument thats overwritten with a public variable with 2 lines of code
 
Beings you're being a messy coder I'll clean it up a little because i'm bored :P

Code:
Public Function DisplayImage(ctlImageControl As Control) As String
Dim strImagepath As Variant
On Error GoTo Err_DisplayImage
'
'PATH to DEFAULT FOLDER
'======================
strImagePath = "c:\temp\" & intPath & ".jpg"
strResult = ""
'
With ctlImageControl

.Visible = True
.Picture = strImagepath

End With

Exit_DisplayImage:
DisplayImage = strResult
Exit Function

Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "No image specified"
Resume Exit_DisplayImage:
'
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function
 
We all learn something everyday. I defer to your greater knowledge - perhaps you can take this thread over now. At least I got Cereldine on the right track.
 
Hey it was a joke, just didn't see the point in letting the user say c is x then saying a = b then c = a whilst you could have just said c = b, no offence intended.
 
No offence taken; the bulk of this code was taken from this forum and as you can see, I have a joined string for the path. When I wrote the code, I wanted to debug it using a separate variable without affecting the core underlying code which was not mine. I appreciate that I have coded it with an extra variable; I was just lazy in not taking it out afterwards. ps my religion is BoE





Bank of England
 

Users who are viewing this thread

Back
Top Bottom