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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid and Search Results

Status
Not open for further replies.

jason12776

Technical User
Nov 15, 2001
93
US
I have a project where I connect an ADO control to an Access 2000 database, and using a datagrid as the result of a search. When clicking through the ADO, a picture will appear with each relavent record, a different picture for each record, now...for testing purposes, I have the datagrid attached to the same ADO and when I try to click on the datagrid to change the record, all my text fields will change, but the picture will not. I get an error, run-time error 13, type mismatch. Here is my code.

Private Sub DataGrid1_Click()
If DataGrid1.ColContaining(txtID.Text) Then
showMovieCover
End If
End Sub

I doubt I'm using the datagrid properly for this. Any assistance will be greatly appreciated.

Cheers.

The code for the showMovieCover is:
Private Sub showMovieCover()
Dim fso
Dim image
Dim noImage

image = "C:\program files\DVD\Covers\" & txtID.Text & ".jpg"
' used if no image is avaliable
noImage = "C:\program files\DVD\Covers\none.jpg"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.fileexists(image) = True Then
Picture1.Picture = LoadPicture(image)
Picture1.AutoSize = True
Else
Picture1.Picture = LoadPicture(noImage)
Picture1.AutoSize = True
End If
End Sub
 
ColContaining returns the column index of the x coordiante of where the mouse is located - x being a number and therefore the type mismatch.

Use the column index of the column where the file name is located.
If Column 5 has the file name, then:
DataGrid1.Columns(5).Text

If there are several columns containing different file names then:
txtID.Text = DataGrid1.Columns(DataGrid1.Col).Text

You may have to fist determine if the column is one with a file name:
With DataGrid1
Select CAse .Col
Case 4,5,6 'Columns with image file names
txtID.Text = .Columns(.Col).Text

End Select
End With

And, it may be even better to use the RowColChange event:

Private Sub DBGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)

With DataGrid1
If LastCol <> .Col then
Select CAse .Col
Case 4,5,6 'Columns with image file names
txtID.Text = .Columns(.Col).Text

End Select
End If
End With

End Sub

[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top