Image Link in Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I'm trying to figure out how to create a field so that a screen shot can be
entered on a form. Each record would have its own screen shot. I want the
people to be able to add the image without any real trouble, such as having
to go into the design window.

The biggest problem I think I have right now is that I don't have the actual
images. I just have to make the field so other people can add their files.
Does anyone have any ideas as to how I might be able to do this?

(Also, so you know how detailed this explanation might have to be, I have
extremely limited experience in Access. I also have no experience with
coding.)

Thank you very very much!

~xylo
 
Include a text field, ImagePath, in the underlying table to store the path to
the image. This is far more efficient than storing the images in the
database. The following code is from the click event procedure of an 'Add
Image' button on a form bound to this table. An image control, Image1, is
included in the form. After adding the image control in design view delete
its Picture property's value as this will be set in code at runtime:

Private Sub cmdAddImage_Click()

On Error GoTo Err_Handler

Dim OpenDlg As New BrowseForFileClass
Dim strPath As String
Dim strAdditionalTypes As String, strFileList As String

' grab position of cursor
GrabCursor

strFileList = "*.bmp; *.jpg"
strAdditionalTypes = "Image Files (" & strFileList & ") |" & strFileList

' open common 'file open' dialogue and get path to selected file
OpenDlg.DialogTitle = "Select Image File"
OpenDlg.AdditionalTypes = strAdditionalTypes
strPath = OpenDlg.GetFileSpec
Set OpenDlg = Nothing

' if file selected then set Picture property of Image control
' to path to file and enable ImageTitle control
If Len(strPath) > 0 Then
Me.ImagePath = strPath
Me.Image1.Picture = strPath
Me.Image1.Visible = True
End If


Exit_here:
' reset cursor position
ReturnCursor
Exit Sub

Err_Handler:
Select Case Err.Number
Case 2001
Resume
Case Else
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_here
End Select

End Sub

Code in the form's Current event procedure loads the image from the file at
runtime:

Private Sub Form_Current()

GrabCursor

If Not IsNull(Me.ImagePath) Then
Me.Image1.Visible = True
Me.Image1.Picture = Me.ImagePath
Else
Me.Image1.Visible = False
End If

ReturnCursor

End Sub

The code uses Bill Wilson's BrowseForFileClass calss module to open a common
dialogue to select an image file. This can be downloaded freely from:


http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps


It also calls the GrabCursor and ReturnCursor functions from the following
module, basCursor, which should be added to the database:

Option Compare Database
Option Explicit

Type POINTAPI
X As Long
Y As Long
End Type

Declare Function GetCursorPos Lib "User32" (lpPoint As POINTAPI) As Long

Declare Function SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As
Long) As Long

Public lngCursorX As Long, lngCursorY As Long

Public Sub GrabCursor()

Dim dl As Long
Dim pt As POINTAPI

dl = GetCursorPos(pt)
lngCursorX = pt.X
lngCursorY = pt.Y

End Sub

Public Sub ReturnCursor()

SetCursorPos lngCursorX, lngCursorY

End Sub

If the files are JPEGs you might want to suppress the progress message which
pops up when each image is loaded. Methods for dong this can be found at:


http://www.mvps.org/access/api/api0038.htm


Ken Sheridan
Stafford, England
 
Thank you very much for all your help!

Ken Sheridan said:
Include a text field, ImagePath, in the underlying table to store the path to
the image. This is far more efficient than storing the images in the
database. The following code is from the click event procedure of an 'Add
Image' button on a form bound to this table. An image control, Image1, is
included in the form. After adding the image control in design view delete
its Picture property's value as this will be set in code at runtime:

Private Sub cmdAddImage_Click()

On Error GoTo Err_Handler

Dim OpenDlg As New BrowseForFileClass
Dim strPath As String
Dim strAdditionalTypes As String, strFileList As String

' grab position of cursor
GrabCursor

strFileList = "*.bmp; *.jpg"
strAdditionalTypes = "Image Files (" & strFileList & ") |" & strFileList

' open common 'file open' dialogue and get path to selected file
OpenDlg.DialogTitle = "Select Image File"
OpenDlg.AdditionalTypes = strAdditionalTypes
strPath = OpenDlg.GetFileSpec
Set OpenDlg = Nothing

' if file selected then set Picture property of Image control
' to path to file and enable ImageTitle control
If Len(strPath) > 0 Then
Me.ImagePath = strPath
Me.Image1.Picture = strPath
Me.Image1.Visible = True
End If


Exit_here:
' reset cursor position
ReturnCursor
Exit Sub

Err_Handler:
Select Case Err.Number
Case 2001
Resume
Case Else
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_here
End Select

End Sub

Code in the form's Current event procedure loads the image from the file at
runtime:

Private Sub Form_Current()

GrabCursor

If Not IsNull(Me.ImagePath) Then
Me.Image1.Visible = True
Me.Image1.Picture = Me.ImagePath
Else
Me.Image1.Visible = False
End If

ReturnCursor

End Sub

The code uses Bill Wilson's BrowseForFileClass calss module to open a common
dialogue to select an image file. This can be downloaded freely from:


http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps


It also calls the GrabCursor and ReturnCursor functions from the following
module, basCursor, which should be added to the database:

Option Compare Database
Option Explicit

Type POINTAPI
X As Long
Y As Long
End Type

Declare Function GetCursorPos Lib "User32" (lpPoint As POINTAPI) As Long

Declare Function SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As
Long) As Long

Public lngCursorX As Long, lngCursorY As Long

Public Sub GrabCursor()

Dim dl As Long
Dim pt As POINTAPI

dl = GetCursorPos(pt)
lngCursorX = pt.X
lngCursorY = pt.Y

End Sub

Public Sub ReturnCursor()

SetCursorPos lngCursorX, lngCursorY

End Sub

If the files are JPEGs you might want to suppress the progress message which
pops up when each image is loaded. Methods for dong this can be found at:


http://www.mvps.org/access/api/api0038.htm


Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top