Save loaded picture in Steve Lebans code..

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
 
S

Stephen Lebans

Do you want to save the name of the selected file or the actual Image
data?

--

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


Mattias said:
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
 
M

Mattias

Hi

I want to save the name..

Mattias
Stephen Lebans said:
Do you want to save the name of the selected file or the actual Image
data?

--

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


Mattias said:
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
 
S

Stephen Lebans

If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Mattias said:
Hi

I want to save the name..

Mattias
"Stephen Lebans"
wrote in message news:[email protected]...
Do you want to save the name of the selected file or the actual Image
data?

--

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


Mattias said:
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
 
M

Mattias

Hi..

It is more
like:Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]=fLoadP
icture(Your"hPic")
please you correct the syntax again and help me where in your code I can put
this...

Thanks

Mattias


Stephen Lebans said:
If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Mattias said:
Hi

I want to save the name..

Mattias
"Stephen Lebans"
wrote in message news:[email protected]...
Do you want to save the name of the selected file or the actual Image
data?

--

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


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
 
S

Stephen Lebans

Mattias let's start over.
1) You should only be using my code if you are running with the Access
runtime environment or trying to load Transparent Images.

2) Generally the function is called from the Form containing the Image
control you are loading the image into. THerefore when you call it you
simply do something like:
Me.txtImageName]=fLoadPicture(Me.NameOfYourImageControl)


--

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


Mattias said:
Hi..

It is more
like:Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]=fL
oadP
icture(Your"hPic")
please you correct the syntax again and help me where in your code I can put
this...

Thanks

Mattias


"Stephen Lebans"
wrote in message news:%23wgPa%[email protected]...
If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Mattias said:
Hi

I want to save the name..

Mattias
"Stephen Lebans"
wrote in message Do you want to save the name of the selected file or the actual Image
data?

--

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


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
 
M

Mattias

Hi again,

Thanks for trying..

1. Correct, would like to use your code to handle jpg:s etc in a runtime
environment.
2. Have this code below now but unfortunatly it saves "-1" instead of the
image name.
Private Sub AddPicture_Click()
'fLoadPicture Me.ImageFrame, , True
Me.[txtImageName] = fLoadPicture(Me.ImageFrame)
'Call getOpenFileApi1
CallDisplayImage
End Sub

I have a function in a module (se below), it loads and saves without
errors...

Function getOpenFileApi1()
Dim strFilter As String
Dim lngFlags As Long
Dim FileName As String
Dim result As Integer
Dim path As String
'On Error Resume Next
strFilter = ahtAddFilterItem(strFilter, "All Files", "*.*")
strFilter = ahtAddFilterItem(strFilter, "JPEGS (*.dbf)", "*.jpg")
strFilter = ahtAddFilterItem(strFilter, "Bitmaps", "*.bmp")
FileName = ahtCommonFileOpenSave(InitialDir:=CurrentProject.path, _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Välj fil")
If Len(FileName) <> 0 Then
Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName] =
Dir(FileName)
End If
Debug.Print Hex(lngFlags)
End Function

Stephen Lebans said:
Mattias let's start over.
1) You should only be using my code if you are running with the Access
runtime environment or trying to load Transparent Images.

2) Generally the function is called from the Form containing the Image
control you are loading the image into. THerefore when you call it you
simply do something like:
Me.txtImageName]=fLoadPicture(Me.NameOfYourImageControl)


--

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


Mattias said:
Hi..

It is more
like:Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]=fL
oadP
icture(Your"hPic")
please you correct the syntax again and help me where in your code I can put
this...

Thanks

Mattias


"Stephen Lebans"
wrote in message news:%23wgPa%[email protected]...
If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Hi

I want to save the name..

Mattias
"Stephen Lebans"
<[email protected]>
wrote in message Do you want to save the name of the selected file or the actual
Image
data?

--

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


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
 
S

Stephen Lebans

Mattias I just looked at the source code and the fLoadPicture function
returns a Boolean value to signal whether the call was successful or
not. To return the FileName selected you have to pass an empty string
variable and when the function returns this var will contain the
selected file. Looking at it now I probably should have the function
return the filename but I must have had my reasons when I designed the
function

Dim blRet as Boolean
Dim sFileName as string
blRet= fLoadPicture(Me.ImageFrame, sFileName)
if blRet then Me.[txtImageName] = sFileName

Good Luck
--

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


Mattias said:
Hi again,

Thanks for trying..

1. Correct, would like to use your code to handle jpg:s etc in a runtime
environment.
2. Have this code below now but unfortunatly it saves "-1" instead of the
image name.
Private Sub AddPicture_Click()
'fLoadPicture Me.ImageFrame, , True
Me.[txtImageName] = fLoadPicture(Me.ImageFrame)
'Call getOpenFileApi1
CallDisplayImage
End Sub

I have a function in a module (se below), it loads and saves without
errors...

Function getOpenFileApi1()
Dim strFilter As String
Dim lngFlags As Long
Dim FileName As String
Dim result As Integer
Dim path As String
'On Error Resume Next
strFilter = ahtAddFilterItem(strFilter, "All Files", "*.*")
strFilter = ahtAddFilterItem(strFilter, "JPEGS (*.dbf)", "*.jpg")
strFilter = ahtAddFilterItem(strFilter, "Bitmaps", "*.bmp")
FileName = ahtCommonFileOpenSave(InitialDir:=CurrentProject.path, _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Välj fil")
If Len(FileName) <> 0 Then
Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName] =
Dir(FileName)
End If
Debug.Print Hex(lngFlags)
End Function

"Stephen Lebans"
wrote in message news:[email protected]...
Mattias let's start over.
1) You should only be using my code if you are running with the Access
runtime environment or trying to load Transparent Images.

2) Generally the function is called from the Form containing the Image
control you are loading the image into. THerefore when you call it you
simply do something like:
Me.txtImageName]=fLoadPicture(Me.NameOfYourImageControl)


--

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


Mattias said:
Hi..

It is more
like:Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]=fL
oadP
icture(Your"hPic")
please you correct the syntax again and help me where in your code
I
can put
this...

Thanks

Mattias


"Stephen Lebans"
wrote in message If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Hi

I want to save the name..

Mattias
"Stephen Lebans"
<[email protected]>
wrote in message Do you want to save the name of the selected file or the actual
Image
data?

--

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


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
 
M

Mattias

Hi and thank you for all your help...that did the trick...all working fine
now!

Mattias
Stephen Lebans said:
Mattias I just looked at the source code and the fLoadPicture function
returns a Boolean value to signal whether the call was successful or
not. To return the FileName selected you have to pass an empty string
variable and when the function returns this var will contain the
selected file. Looking at it now I probably should have the function
return the filename but I must have had my reasons when I designed the
function

Dim blRet as Boolean
Dim sFileName as string
blRet= fLoadPicture(Me.ImageFrame, sFileName)
if blRet then Me.[txtImageName] = sFileName

Good Luck
--

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


Mattias said:
Hi again,

Thanks for trying..

1. Correct, would like to use your code to handle jpg:s etc in a runtime
environment.
2. Have this code below now but unfortunatly it saves "-1" instead of the
image name.
Private Sub AddPicture_Click()
'fLoadPicture Me.ImageFrame, , True
Me.[txtImageName] = fLoadPicture(Me.ImageFrame)
'Call getOpenFileApi1
CallDisplayImage
End Sub

I have a function in a module (se below), it loads and saves without
errors...

Function getOpenFileApi1()
Dim strFilter As String
Dim lngFlags As Long
Dim FileName As String
Dim result As Integer
Dim path As String
'On Error Resume Next
strFilter = ahtAddFilterItem(strFilter, "All Files", "*.*")
strFilter = ahtAddFilterItem(strFilter, "JPEGS (*.dbf)", "*.jpg")
strFilter = ahtAddFilterItem(strFilter, "Bitmaps", "*.bmp")
FileName = ahtCommonFileOpenSave(InitialDir:=CurrentProject.path, _
Filter:=strFilter, FilterIndex:=1, Flags:=lngFlags, _
DialogTitle:="Välj fil")
If Len(FileName) <> 0 Then
Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName] =
Dir(FileName)
End If
Debug.Print Hex(lngFlags)
End Function

"Stephen Lebans"
wrote in message news:[email protected]...
Mattias let's start over.
1) You should only be using my code if you are running with the Access
runtime environment or trying to load Transparent Images.

2) Generally the function is called from the Form containing the Image
control you are loading the image into. THerefore when you call it you
simply do something like:
Me.txtImageName]=fLoadPicture(Me.NameOfYourImageControl)


--

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


Hi..

It is more

like:Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]=fL
oadP
icture(Your"hPic")
please you correct the syntax again and help me where in your code I
can put
this...

Thanks

Mattias


"Stephen Lebans"
<[email protected]>
wrote in message If I understand you correctly:

Forms![Objektmottagning]![ObjektmottagningradCtl]![txtImageName]
=fLoadPicture(WhateverIsTheNameOfyourImageControl)

--

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


Hi

I want to save the name..

Mattias
"Stephen Lebans"
<[email protected]>
wrote in message Do you want to save the name of the selected file or the actual
Image
data?

--

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


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
 

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

Similar Threads


Top