M
Mattias
Can someone please assist me in updating this code below to save the loaded
picture, if not =null to the current record.
something like:
Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName] =
Dir(FileName)
Thanks in advance
Mattias
Public Function fLoadPicture(ctl As Access.Image, Optional strfName As
String = "", Optional AutoSize As Boolean = False) As Boolean
' Inputs
' ctl -> Access Image control
' strfName -> Optional name of Image file to load and bypass File Dialog
On Error GoTo Err_fLoadPicture
' Temp Vars
Dim lngRet As Long
Dim blRet As Boolean
' Our StdPicture object returned by LoadPicture
Dim hPic As Object
' Were we passed the Optional FileName and Path
If Len(strfName & vbNullString) = 0 Then
' Call the File Common Dialog Window
Dim clsDialog As Object
Dim strTemp As String
Set clsDialog = New clsCommonDialog
' Fill in our structure
clsDialog.Filter = "All (*.*)" & Chr$(0) & "*.*" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "JPEG (*.JPG)" & Chr$(0) & "*.JPG"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Gif (*.GIF)" & Chr$(0) & "*.GIF"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Bitmap (*.BMP)" & Chr$(0) &
"*.BMP" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Enhanced Metafile (*.EMF)" &
Chr$(0) & "*.EMF" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Windows Metafile (*.WMF)" &
Chr$(0) & "*.WMF" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Icon (*.ICO)" & Chr$(0) & "*.ICO"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Cursor (*.CUR)" & Chr$(0) &
"*.CUR" & Chr$(0)
clsDialog.hDC = 0
clsDialog.MaxFileSize = 256
clsDialog.Max = 256
clsDialog.FileTitle = vbNullString
clsDialog.DialogTitle = "Please Select an Image File"
clsDialog.InitDir = vbNullString
clsDialog.DefaultExt = vbNullString
' Display the File Dialog
clsDialog.ShowOpen
' See if user clicked Cancel or even selected
' the very same file already selected
strfName = clsDialog.FileName
If Len(strfName & vbNullString) = 0 Then
' Raise the exception
Err.Raise vbObjectError + 513, "LoadJpegGif.modStdPic", _
"Please Select a Valid JPEG or GIF File"
End If
' If we jumped to here then user supplied a FileName
End If
' It may take a few seconds to render larger JPEGs.
' Set the MousePointer to "HOURGLASS"
Application.Screen.MousePointer = 11
' Load the Picture as a StandardPicture object
Set hPic = LoadPicture(strfName)
If hPic = 0 Then
Err.Raise vbObjectError + 514, "LoadJpegGif.modStdPic", _
"Please Select a Valid JPEG or GIF File"
End If
' Call our function to convert the StdPicture object
' into a DIB wrapped within an Enhanced Metafile
'blRet = fStdPicToImageData(hPic, ctl, , AutoSize)
' need error handling here
' Cleanup
fLoadPicture = True
Exit_LoadPic:
' Set the MousePointer back to Default
Application.Echo True
Application.Screen.MousePointer = 0
Err.Clear
Set hPic = Nothing
Set clsDialog = Nothing
Exit Function
Err_fLoadPicture:
fLoadPicture = False
Application.Screen.MousePointer = 0
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume Exit_LoadPic
End Function
picture, if not =null to the current record.
something like:
Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName] =
Dir(FileName)
Thanks in advance
Mattias
Public Function fLoadPicture(ctl As Access.Image, Optional strfName As
String = "", Optional AutoSize As Boolean = False) As Boolean
' Inputs
' ctl -> Access Image control
' strfName -> Optional name of Image file to load and bypass File Dialog
On Error GoTo Err_fLoadPicture
' Temp Vars
Dim lngRet As Long
Dim blRet As Boolean
' Our StdPicture object returned by LoadPicture
Dim hPic As Object
' Were we passed the Optional FileName and Path
If Len(strfName & vbNullString) = 0 Then
' Call the File Common Dialog Window
Dim clsDialog As Object
Dim strTemp As String
Set clsDialog = New clsCommonDialog
' Fill in our structure
clsDialog.Filter = "All (*.*)" & Chr$(0) & "*.*" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "JPEG (*.JPG)" & Chr$(0) & "*.JPG"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Gif (*.GIF)" & Chr$(0) & "*.GIF"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Bitmap (*.BMP)" & Chr$(0) &
"*.BMP" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Enhanced Metafile (*.EMF)" &
Chr$(0) & "*.EMF" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Windows Metafile (*.WMF)" &
Chr$(0) & "*.WMF" & Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Icon (*.ICO)" & Chr$(0) & "*.ICO"
& Chr$(0)
clsDialog.Filter = clsDialog.Filter & "Cursor (*.CUR)" & Chr$(0) &
"*.CUR" & Chr$(0)
clsDialog.hDC = 0
clsDialog.MaxFileSize = 256
clsDialog.Max = 256
clsDialog.FileTitle = vbNullString
clsDialog.DialogTitle = "Please Select an Image File"
clsDialog.InitDir = vbNullString
clsDialog.DefaultExt = vbNullString
' Display the File Dialog
clsDialog.ShowOpen
' See if user clicked Cancel or even selected
' the very same file already selected
strfName = clsDialog.FileName
If Len(strfName & vbNullString) = 0 Then
' Raise the exception
Err.Raise vbObjectError + 513, "LoadJpegGif.modStdPic", _
"Please Select a Valid JPEG or GIF File"
End If
' If we jumped to here then user supplied a FileName
End If
' It may take a few seconds to render larger JPEGs.
' Set the MousePointer to "HOURGLASS"
Application.Screen.MousePointer = 11
' Load the Picture as a StandardPicture object
Set hPic = LoadPicture(strfName)
If hPic = 0 Then
Err.Raise vbObjectError + 514, "LoadJpegGif.modStdPic", _
"Please Select a Valid JPEG or GIF File"
End If
' Call our function to convert the StdPicture object
' into a DIB wrapped within an Enhanced Metafile
'blRet = fStdPicToImageData(hPic, ctl, , AutoSize)
' need error handling here
' Cleanup
fLoadPicture = True
Exit_LoadPic:
' Set the MousePointer back to Default
Application.Echo True
Application.Screen.MousePointer = 0
Err.Clear
Set hPic = Nothing
Set clsDialog = Nothing
Exit Function
Err_fLoadPicture:
fLoadPicture = False
Application.Screen.MousePointer = 0
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume Exit_LoadPic
End Function