G
Guest
I am a newbie trying to replicate the 'browse for image' function explained
in the post titled: "OLE Object- the real question."After following the
instructions from the above post, I get an error when I click on the image
frame (to select an image to put in the form). I get the error message:
"Compile Error: User-defined type not defined." The Visual Basic window
opens and "Dim dlgFilePick As FileDialog" is highlit as the trouble spot.
When I go from design to form view I get a run time error and then hitting
the debug button highlights the "Me.Image30.Picture = Me!
filePath" code. I would appreciate someone letting me know what I am doing
wrong.
Here is what I am doing:
-Using Access 2003
1.) I have created a field in my table called 'FilePath'
2.) In the 'On Current' event of the form, I have pasted the following code
into the code builder window ('Image30' is the name of the image frame):
*********code start************
Private Sub Form_Current()
Me.Image30.Picture = Me!filePath
End Sub
*********code end************
3.) In the 'On Click' event for the unbound image frame (in the code builder)
I pasted the following:
*********code start************
Private Sub Image30_Click()
Dim strFilename As String, strFind As String
Dim lngID As Long
strFilename = GetTheFilename("Browse to the file")
If strFilename = "Cancelled" Then
Exit Sub
End If
Me!filePath = strFilename
lngID = Me!ItemID
strFind = "[ItemID]=" & lngID
Echo False
Me.Requery
Me.Recordset.FindFirst strFind
Echo True
End Sub
*********code end************
4.) This code was pasted in Module2(code) window:
*********code start************
Function GetTheFilename(strTitle As String) As String
Dim strFilename As String
Dim dlgFilePick As FileDialog
Dim vrtSelectedItem As Variant
On Error GoTo Err_GetFilename
Set dlgFilePick = Application.FileDialog(msoFileDialogFilePicker)
With dlgFilePick
.title = strTitle
'Let user select only one file
.AllowMultiSelect = False
If .Show = -1 Then
'The user pressed the action button.
GetTheFilename = .SelectedItems(1)
Else
'The user pressed Cancel.
GetTheFilename = "Cancelled"
End If
End With
Exit_GetFilename:
Set dlgFilePick = Nothing
Exit Function
Err_GetFilename:
MsgBox "Error " & Err.Number & ": " & Err.Description, ,
"GetTheFilename"
Resume Exit_GetFilename
End Function
*********code end************
in the post titled: "OLE Object- the real question."After following the
instructions from the above post, I get an error when I click on the image
frame (to select an image to put in the form). I get the error message:
"Compile Error: User-defined type not defined." The Visual Basic window
opens and "Dim dlgFilePick As FileDialog" is highlit as the trouble spot.
When I go from design to form view I get a run time error and then hitting
the debug button highlights the "Me.Image30.Picture = Me!
filePath" code. I would appreciate someone letting me know what I am doing
wrong.
Here is what I am doing:
-Using Access 2003
1.) I have created a field in my table called 'FilePath'
2.) In the 'On Current' event of the form, I have pasted the following code
into the code builder window ('Image30' is the name of the image frame):
*********code start************
Private Sub Form_Current()
Me.Image30.Picture = Me!filePath
End Sub
*********code end************
3.) In the 'On Click' event for the unbound image frame (in the code builder)
I pasted the following:
*********code start************
Private Sub Image30_Click()
Dim strFilename As String, strFind As String
Dim lngID As Long
strFilename = GetTheFilename("Browse to the file")
If strFilename = "Cancelled" Then
Exit Sub
End If
Me!filePath = strFilename
lngID = Me!ItemID
strFind = "[ItemID]=" & lngID
Echo False
Me.Requery
Me.Recordset.FindFirst strFind
Echo True
End Sub
*********code end************
4.) This code was pasted in Module2(code) window:
*********code start************
Function GetTheFilename(strTitle As String) As String
Dim strFilename As String
Dim dlgFilePick As FileDialog
Dim vrtSelectedItem As Variant
On Error GoTo Err_GetFilename
Set dlgFilePick = Application.FileDialog(msoFileDialogFilePicker)
With dlgFilePick
.title = strTitle
'Let user select only one file
.AllowMultiSelect = False
If .Show = -1 Then
'The user pressed the action button.
GetTheFilename = .SelectedItems(1)
Else
'The user pressed Cancel.
GetTheFilename = "Cancelled"
End If
End With
Exit_GetFilename:
Set dlgFilePick = Nothing
Exit Function
Err_GetFilename:
MsgBox "Error " & Err.Number & ": " & Err.Description, ,
"GetTheFilename"
Resume Exit_GetFilename
End Function
*********code end************