I have a subform that has a cell on it and when you click on the cell, it will tell another subform to display data based upon the unique id. At the same time I want the second subform (call it data) to display an image if an image exists.
I have a function that is called updatePath, that if called is supposed to display the image (if it exists, otherwise just a blank image). The first problem is that I cannot seem to get anything to call this Function. Form_Load/Query/DataSetChange/GotFocus all do not call the function (I will know because of the MsgBox).
The only time the function is getting called is after a pop up form is launched, and the window is closed. So it does go into the function, but for some reason after the first MsgBox displays the entered image path, the 2nd MsgBox displays 'Type Mismatch'
Below is the current code:
' Function to check and see if the file exists
Function FileExists(strPath As String, Optional lngType As Long) As Boolean
On Error Resume Next
FileExists = Len(Dir(strPath, lngType)) > 0
End Function
' Function used to update what image to display
Function updatePath(img As String)
Dim filePath As String
MsgBox img
If (img) Then
filePath = CurrentProject.Path & "\Images\" & img
MsgBox filePath
If (FileExists(filePath) = True) Then
[Forms]![frmSearch].frmComicDetailsSub.Form.imgImage.Picture = filePath
Else
[Forms]![frmSearch].frmComicDetailsSub.Form.imgImage.Picture = CurrentProject.Path & "\Images\no_image.gif"
End If
End If
End Function
' Button that when clicked on opens a form to enter the image path/name
Private Sub cmdChangePath_Click()
On Error GoTo Err_cmdChangePath_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmImagePath"
stLinkCriteria = "[comic_id]= " & Me![comic_id]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
ans = updatePath(([image]))
Me.Requery
Exit_cmdChangePath_Click:
Exit Sub
Err_cmdChangePath_Click:
MsgBox Err.description
Resume Exit_cmdChangePath_Click
End Sub
' From here on down I am trying to get the image to update
Private Sub Form_DataSetChange()
ans = updatePath([image])
End Sub
Private Sub Form_GotFocus()
ans = updatePath([image])
End Sub
Private Sub Form_Load()
If ([image]) Then
ans = updatePath([image])
End If
End Sub
Private Sub Form_Query()
ans = updatePath([image])
End Sub
I have a function that is called updatePath, that if called is supposed to display the image (if it exists, otherwise just a blank image). The first problem is that I cannot seem to get anything to call this Function. Form_Load/Query/DataSetChange/GotFocus all do not call the function (I will know because of the MsgBox).
The only time the function is getting called is after a pop up form is launched, and the window is closed. So it does go into the function, but for some reason after the first MsgBox displays the entered image path, the 2nd MsgBox displays 'Type Mismatch'
Below is the current code:
' Function to check and see if the file exists
Function FileExists(strPath As String, Optional lngType As Long) As Boolean
On Error Resume Next
FileExists = Len(Dir(strPath, lngType)) > 0
End Function
' Function used to update what image to display
Function updatePath(img As String)
Dim filePath As String
MsgBox img
If (img) Then
filePath = CurrentProject.Path & "\Images\" & img
MsgBox filePath
If (FileExists(filePath) = True) Then
[Forms]![frmSearch].frmComicDetailsSub.Form.imgImage.Picture = filePath
Else
[Forms]![frmSearch].frmComicDetailsSub.Form.imgImage.Picture = CurrentProject.Path & "\Images\no_image.gif"
End If
End If
End Function
' Button that when clicked on opens a form to enter the image path/name
Private Sub cmdChangePath_Click()
On Error GoTo Err_cmdChangePath_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmImagePath"
stLinkCriteria = "[comic_id]= " & Me![comic_id]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
ans = updatePath(([image]))
Me.Requery
Exit_cmdChangePath_Click:
Exit Sub
Err_cmdChangePath_Click:
MsgBox Err.description
Resume Exit_cmdChangePath_Click
End Sub
' From here on down I am trying to get the image to update
Private Sub Form_DataSetChange()
ans = updatePath([image])
End Sub
Private Sub Form_GotFocus()
ans = updatePath([image])
End Sub
Private Sub Form_Load()
If ([image]) Then
ans = updatePath([image])
End If
End Sub
Private Sub Form_Query()
ans = updatePath([image])
End Sub