J
JohnB
Hi.
I've been shoehorning some objects from a sample "Images in Access" mdb into
one of my mdbs, both Access 97 and mostly successfully. But when I use a
certain form as a subform in my mdb and run it, I get a Compile Error:
"Variable Not Defined" message. This does not occur when the form is used in
the origin mdb, as a main form. The problem code is "Cancel = True" and I've
just commented-out the line, with no obvious ill effects (although I believe
this will allow an unwanted error message to appear in certain
circumstances). Now I've just added a command button (cmdLinkToPhoto) to the
subform with some code which includes another "Cancel = True" line and this
errors as well. Can anyone tell me why this is happening when I use the form
as a subform in a different mdb and how to fix it? I've copied the full code
for the form below and left both "Cancel = True" lines commented-out and
marked in this post with a long line of X's.
Thanks for any help, JohnB
Option Compare Database
Option Explicit
Dim ysnSaveButtonClicked As Boolean
Private Function Validate() As Boolean
' Purpose : Validate that all the information has been entered before
saving
' Parameters : None
' Returns : Boolean: True if there is information; False if any field is
null or zero-length string
' Created/Modified : 8/9/99,
On Error GoTo PROC_ERR
Dim msg As String
'If IsNull(Me![txtImageShortName]) Or Me![txtImageShortName] = "" Or _
'IsNull(Me![txtImageName]) Or Me![txtImageName] = "" Or _
If IsNull(Me![txtImagePathAndFile]) Or Me![txtImagePathAndFile] = "" Or
_
IsNull(Me![imgTheImage].Picture) Or Me![imgTheImage].Picture =
"" Then
msg = "To save, there must be information in Image Short Name, Image
Name, and the Image itself."
msg = msg & "Please enter the information and try again or Undo."
MsgBox msg, vbOKOnly + vbInformation, "Images in Access Example"
Validate = False
Else
Validate = True
End If
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Err: " & Err.Number & " : " & Err.Description & _
" in Function Validate()", vbCritical, "Images in Access Example"
Resume PROC_EXIT
End Function
Private Sub cmdLinkToPhoto_Click()
' 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/Modified : 6/24/99,
'On Error GoTo ErrHandler
If Not IsNull(Me![txtImagePathAndFile2]) Then
MsgBox "Photo already allocated"
'Cancel = True XXXXXXXXXXXXXXXXXXXXXXXXX
End If
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, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")
If Len(strPathAndFile) > 0 Then
MsgBox "You selected: " & strPathAndFile
Me![imgTheImage].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", , "Images in Access Example"
' Cancel = True XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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 Sub
Private Sub cmdUndo_Click()
' Purpose : Undo changes to recrod
' Parameters : None
' Created/Modified : 10/8/99,
On Error GoTo Err_cmdUndo_Click
If Me.Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
DoCmd.Close acForm, Me.Name
Exit_cmdUndo_Click:
Exit Sub
Err_cmdUndo_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdUndo_Click", vbExclamation, "Images in Access Example"
Resume Exit_cmdUndo_Click
End Sub
Private Sub cmdSave_Click()
' Purpose : Save the Record
' Parameters : None
' Created/Modified : 10/8/99,
On Error GoTo Err_cmdSave_Click
'If Validated, Save; if not, just return to Form
Me![txtImagePathAndFile] = Me![imgTheImage].Picture
If Validate Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Echo False
' Forms![frmImageFileSummaryList].Requery
DoCmd.Echo True
DoCmd.Close acForm, Me.Name
End If
Exit_cmdSave_Click:
On Error Resume Next
Exit Sub
Err_cmdSave_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdSave_Click", vbExclamation, "Images in Access Example"
Resume Exit_cmdSave_Click
End Sub
Private Sub Form_Current()
Me![imgTheImage].Picture = ""
End Sub
I've been shoehorning some objects from a sample "Images in Access" mdb into
one of my mdbs, both Access 97 and mostly successfully. But when I use a
certain form as a subform in my mdb and run it, I get a Compile Error:
"Variable Not Defined" message. This does not occur when the form is used in
the origin mdb, as a main form. The problem code is "Cancel = True" and I've
just commented-out the line, with no obvious ill effects (although I believe
this will allow an unwanted error message to appear in certain
circumstances). Now I've just added a command button (cmdLinkToPhoto) to the
subform with some code which includes another "Cancel = True" line and this
errors as well. Can anyone tell me why this is happening when I use the form
as a subform in a different mdb and how to fix it? I've copied the full code
for the form below and left both "Cancel = True" lines commented-out and
marked in this post with a long line of X's.
Thanks for any help, JohnB
Option Compare Database
Option Explicit
Dim ysnSaveButtonClicked As Boolean
Private Function Validate() As Boolean
' Purpose : Validate that all the information has been entered before
saving
' Parameters : None
' Returns : Boolean: True if there is information; False if any field is
null or zero-length string
' Created/Modified : 8/9/99,
On Error GoTo PROC_ERR
Dim msg As String
'If IsNull(Me![txtImageShortName]) Or Me![txtImageShortName] = "" Or _
'IsNull(Me![txtImageName]) Or Me![txtImageName] = "" Or _
If IsNull(Me![txtImagePathAndFile]) Or Me![txtImagePathAndFile] = "" Or
_
IsNull(Me![imgTheImage].Picture) Or Me![imgTheImage].Picture =
"" Then
msg = "To save, there must be information in Image Short Name, Image
Name, and the Image itself."
msg = msg & "Please enter the information and try again or Undo."
MsgBox msg, vbOKOnly + vbInformation, "Images in Access Example"
Validate = False
Else
Validate = True
End If
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Err: " & Err.Number & " : " & Err.Description & _
" in Function Validate()", vbCritical, "Images in Access Example"
Resume PROC_EXIT
End Function
Private Sub cmdLinkToPhoto_Click()
' 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/Modified : 6/24/99,
'On Error GoTo ErrHandler
If Not IsNull(Me![txtImagePathAndFile2]) Then
MsgBox "Photo already allocated"
'Cancel = True XXXXXXXXXXXXXXXXXXXXXXXXX
End If
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, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
strPathAndFile = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Choose an Image File")
If Len(strPathAndFile) > 0 Then
MsgBox "You selected: " & strPathAndFile
Me![imgTheImage].Picture = strPathAndFile
Else
MsgBox "You didn't select a file", , "Images in Access Example"
' Cancel = True XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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 Sub
Private Sub cmdUndo_Click()
' Purpose : Undo changes to recrod
' Parameters : None
' Created/Modified : 10/8/99,
On Error GoTo Err_cmdUndo_Click
If Me.Dirty = True Then
DoCmd.RunCommand acCmdUndo
End If
DoCmd.Close acForm, Me.Name
Exit_cmdUndo_Click:
Exit Sub
Err_cmdUndo_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdUndo_Click", vbExclamation, "Images in Access Example"
Resume Exit_cmdUndo_Click
End Sub
Private Sub cmdSave_Click()
' Purpose : Save the Record
' Parameters : None
' Created/Modified : 10/8/99,
On Error GoTo Err_cmdSave_Click
'If Validated, Save; if not, just return to Form
Me![txtImagePathAndFile] = Me![imgTheImage].Picture
If Validate Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Echo False
' Forms![frmImageFileSummaryList].Requery
DoCmd.Echo True
DoCmd.Close acForm, Me.Name
End If
Exit_cmdSave_Click:
On Error Resume Next
Exit Sub
Err_cmdSave_Click:
MsgBox "Error " & Err.Number & " : " & Err.Description & " in
cmdSave_Click", vbExclamation, "Images in Access Example"
Resume Exit_cmdSave_Click
End Sub
Private Sub Form_Current()
Me![imgTheImage].Picture = ""
End Sub