G
Gina Whipp
desireemm,
Removed previous postings so as to avoid confusion. DO THIS ON A BACK-UP...
If you make a boo-boo you want to retain the original!!!
Step 1
Copy and Paste the below in a module and named modImages and save when done
***START OF CODE***
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 0 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\",
Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = "Image found and displayed."
End If
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 = "Can't find image in the specified name."
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
***END OF CODE***
Step 2
In your table you will need two fields ImagePath and ImageNote
Step 3 - Do following while form is in Design View
a. On your form place both fields and name then txtImagePath and
txtImageNote
b. Also add an Image Control, unbound and name it imgImage NOTE: While
adding this control it wants you to select an Image, do it and after you
have created the control go to Properties and remove anything on the Picture
line. It will ask you a question and YES you want to set the picture to
*NONE*.)
Step 4 - Still in Design View of the form
Place two command buttons, one named cmdAddImage (Make the caption say the
same) the other name cmdClearImage (Make the caption say the same). Below
is the code for the buttons... Place the code in the On_Click event of the
prospective buttons...
'***cmdAddAimage****
' Purpose : Use the API to open the Windows Common Dialog for the user to
select a file
' Parameters : Cancel -- if set to true on Exit, cancels opening the form
' Created: 6/24/99
'On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
Dim strPathAndFile As String
Me.AllowDeletions = False
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", "*.JPG;*.JFF,*.GIF,*.TIF")
strFilter = ahtAddFilterItem(strFilter, "Uncompressed Image Files
(*.bmp, *.wmf)", "*.BMP, *.WMF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="S:\Cleveland\Jobs\",
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:="Choose an
Image")
If Len(strPathAndFile) > 0 Then
Me.txtImagePath = strPathAndFile
Me.imgImage.Picture = Me.txtImagePath
Else
MsgBox "You didn't select a file", , "Images"
DoCmd.CancelEvent
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
Form_Open", vbExclamation, "Images in Access Example"
Resume Exit_Sub
'***END OF CODE
'***cmdClearImage
On Error Resume Next
Me.txtImagePath = Null
Me.imgImage.Picture = ""
'***END OF CODE
Step 4 - Save but remain in Design View of the form. Copy paste the code
below at the bottom of the Code WIndow and Save
'***START OF CODE
Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!imgImage, Me!txtImagePath)
End Sub
'***END OF CODE
Step 5
Place...
CallDisplayImage
....on the After_Update of the form OR On_Current of the form AND in the
After_Update of txtImagePath
ALL DONE! Now all you need to do is load the image paths into the database.
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II
http://www.regina-whipp.com/index_files/TipList.htm
Removed previous postings so as to avoid confusion. DO THIS ON A BACK-UP...
If you make a boo-boo you want to retain the original!!!
Step 1
Copy and Paste the below in a module and named modImages and save when done
***START OF CODE***
Option Compare Database
Option Explicit
Public Function DisplayImage(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 0 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\",
Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = "Image found and displayed."
End If
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 = "Can't find image in the specified name."
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
***END OF CODE***
Step 2
In your table you will need two fields ImagePath and ImageNote
Step 3 - Do following while form is in Design View
a. On your form place both fields and name then txtImagePath and
txtImageNote
b. Also add an Image Control, unbound and name it imgImage NOTE: While
adding this control it wants you to select an Image, do it and after you
have created the control go to Properties and remove anything on the Picture
line. It will ask you a question and YES you want to set the picture to
*NONE*.)
Step 4 - Still in Design View of the form
Place two command buttons, one named cmdAddImage (Make the caption say the
same) the other name cmdClearImage (Make the caption say the same). Below
is the code for the buttons... Place the code in the On_Click event of the
prospective buttons...
'***cmdAddAimage****
' Purpose : Use the API to open the Windows Common Dialog for the user to
select a file
' Parameters : Cancel -- if set to true on Exit, cancels opening the form
' Created: 6/24/99
'On Error GoTo ErrHandler
Dim lngFlags As Long
Dim strFilter As String
Dim strPathAndFile As String
Me.AllowDeletions = False
strFilter = ahtAddFilterItem(strFilter, "Compressed Image Files (*.jpg,
*.jff, *.gif, *.tiff )", "*.JPG;*.JFF,*.GIF,*.TIF")
strFilter = ahtAddFilterItem(strFilter, "Uncompressed Image Files
(*.bmp, *.wmf)", "*.BMP, *.WMF")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="S:\Cleveland\Jobs\",
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:="Choose an
Image")
If Len(strPathAndFile) > 0 Then
Me.txtImagePath = strPathAndFile
Me.imgImage.Picture = Me.txtImagePath
Else
MsgBox "You didn't select a file", , "Images"
DoCmd.CancelEvent
End If
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Exit_Sub:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
Form_Open", vbExclamation, "Images in Access Example"
Resume Exit_Sub
'***END OF CODE
'***cmdClearImage
On Error Resume Next
Me.txtImagePath = Null
Me.imgImage.Picture = ""
'***END OF CODE
Step 4 - Save but remain in Design View of the form. Copy paste the code
below at the bottom of the Code WIndow and Save
'***START OF CODE
Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!imgImage, Me!txtImagePath)
End Sub
'***END OF CODE
Step 5
Place...
CallDisplayImage
....on the After_Update of the form OR On_Current of the form AND in the
After_Update of txtImagePath
ALL DONE! Now all you need to do is load the image paths into the database.
--
Gina Whipp
"I feel I have been denied critical, need to know, information!" - Tremors
II
http://www.regina-whipp.com/index_files/TipList.htm