Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch & updating image

Status
Not open for further replies.

dunnma

Programmer
Aug 25, 2005
16
US
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
 
Firstly, if you want code to run when the user enters a text control on a form, look at the On_Enter event.

Secondly, You will note that [image] may be null when the data set changes. You will need to add some check for that in you updatePath code. This is because Dir(Null) is not valid as null is not a string.

Thirdly, Note that if lngType in your call to FileExists has 16 as a bitwise component, then you will get "." and ".." returned. I am sure you don't need to worry about that since you're probably never going to call FileExists in that way.

So, the reason it may work one time, is because your field [image] is not null at that time.

If you changed the calls to:
ans=Update (Nz([image],CurrentProject.Path & "\Images\no_image.gif"))
Then you might solve the problem of the error but I think the program flow might still need to be addressed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top