Images on an Access Form

  • Thread starter Thread starter Andy Levy
  • Start date Start date
A

Andy Levy

Hi

I have an access form - that should display an image based on a hyperlink
stored as a value on the form . I do not want to store the image in the
database itself as it will make the database size very large - but rather
tell it to display t he image at http://myserver.com/image.jpg. If i put an
http address under the picture property - it does not work.

Also - how can i get an access button to open up a webpage to a specific
address.

Many thanks

AL
 
To show an external graphic, use the Current event of the form to assign the
Picture property of an Image control. Note that this works for Form View
only (not Continuous View forms).

There is always the chance that the file is no longer present, so this
example assumes:
- the string "strFullPath" contains the fully qualified file;
- if the file is no longer present, you want to hide the image control and
in its place show a label named "lblNoImage" that has "No image" in its
Caption.

-------------code starts----------------------
Private Sub Form_Current()
Dim bShow As Boolean
With Me.[NameOfYourImageControlHere]
If FileExists(strFullPath) Then
bShow = True
If .Picture = strFullPath Then
'do nothing
Else
.Picture = strFullPath
End If
End If
If .Visible <> bShow Then
.Visible = bShow
Me.lblNoImage.Visible = Not bShow
End If
End With
End Sub

Public Function FileExists(varFullPath As Variant) As Boolean
On Error Resume Next
If Len(varFullPath) > 0& Then
FileExists = (Len(Dir$(varFullPath)) > 0&)
End If
End Function
-------------code ends----------------------

Use FollowHyperlink to open the web page. If the page contains a Name within
the page, you can use the 3rd part of the hyperlink to specifiy the name.

More info in article:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html
 
Thank you for your answer - it was very helpful

I have my images stored in a directory on the web - but, even having read
the website link you gave i cannot get the image to link from a directory on
the web ie. www.myserver.com/myimage.jpg

I am looking for something that will let me call the following (for exanple)
on the below function : -

Call
FileExists("http://www.microsoft.com/windows/images/homepage/37683a_zone_F.j
pg")
Public Function FileExists(varFullPath As Variant) As Boolean
On Error Resume Next
If Len(varFullPath) > 0& Then
FileExists = (Len(Dir$(varFullPath)) > 0&)
End If
End Function





Allen Browne said:
To show an external graphic, use the Current event of the form to assign the
Picture property of an Image control. Note that this works for Form View
only (not Continuous View forms).

There is always the chance that the file is no longer present, so this
example assumes:
- the string "strFullPath" contains the fully qualified file;
- if the file is no longer present, you want to hide the image control and
in its place show a label named "lblNoImage" that has "No image" in its
Caption.

-------------code starts----------------------
Private Sub Form_Current()
Dim bShow As Boolean
With Me.[NameOfYourImageControlHere]
If FileExists(strFullPath) Then
bShow = True
If .Picture = strFullPath Then
'do nothing
Else
.Picture = strFullPath
End If
End If
If .Visible <> bShow Then
.Visible = bShow
Me.lblNoImage.Visible = Not bShow
End If
End With
End Sub

Public Function FileExists(varFullPath As Variant) As Boolean
On Error Resume Next
If Len(varFullPath) > 0& Then
FileExists = (Len(Dir$(varFullPath)) > 0&)
End If
End Function
-------------code ends----------------------

Use FollowHyperlink to open the web page. If the page contains a Name within
the page, you can use the 3rd part of the hyperlink to specifiy the name.

More info in article:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.
Andy Levy said:
Hi

I have an access form - that should display an image based on a hyperlink
stored as a value on the form . I do not want to store the image in the
database itself as it will make the database size very large - but rather
tell it to display t he image at http://myserver.com/image.jpg. If i
put
an
http address under the picture property - it does not work.

Also - how can i get an access button to open up a webpage to a specific
address.

Many thanks

AL
 
Hi Allen,
I have never worked in this area before so I just had a quick peak at
the issue tonight. You cannot place a URL in the Picture prop of a
standard Access Image control so it's either use the Hyperlink method
you outlined or some method to download the image to your local disk and
then load that image intot he Image control.

I placed the MS INternet Transfer control on an Access Form. I added a
CommandBUtton and an Image control.

Private Sub cmdDload_Click()
On Error GoTo Err_cmdDload_Click
Dim sUrl As String
sUrl = "http://www.lebans.com/images/Hillcrest 4x5grey.jpg"

Dim binarydata() As Byte

binarydata() = Me.ActiveXCtl1.OpenURL(sUrl, icByteArray)

Open "C:\TEMP\image.jpg" For Binary Access Write As #1
Put #1, , binarydata()
Close #1

Me.Image3.Picture = "C:\temp\Image.jpg"

Exit_cmdDload_Click:
Exit Sub

Err_cmdDload_Click:
MsgBox Err.Description
Resume Exit_cmdDload_Click

End Sub


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Thanks, Stephen.

Well, there you go, Andy. A personal response from the world's leading
expert on matters graphical in Access. :-)
 
Thank you so much for the info.

I have tried this method, but I get an activex licence error, stating i do
not have a licence to use the 'MS INternet Transfer' control. I am using MS
Access 2000 (MS Office Pro 2K). Microsoft offer a download to help with
this problem (i think) - but it is only available for the developer edition.

Why would access 2k offer it as a control if you cant use it ?

Many thanks again

Andy
 
Back
Top