Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Showing different images in one imagebox control in vb6

Showing different images in one imagebox control in vb6

Showing different images in one imagebox control in vb6

Dear All,

I have written a database for student profiles and encountered a problem when using mshflexgrid control. I have successfully populated the mshflexgrid control with records from my access database, put one imagebox in the same form where the mshflexgrid is.

What I want is when the user clicks an ID of a student in the grid control the image should change and show that particular student's photo. I tried putting in some code and it's loading the images but not able to show images when I randomly click an ID from the grid. What it's doing is that when I click the first record from the grid, I must click each record in order to show each images perfectly but will not show right image if I skip a record and click anywhere. I have to go like, click first record, second, third and so forth till I reach the end. And when I reach the end it won't work if I go back and click on the first record, it shows only the last image of the last record. I have included 'rs.MoveNext' in my code because if I don't then the images don't change when I click through the IDs in the grid but only the image of the first student in the database shows. This is my code:

Private Sub MSHflexGrid1_click()
On Error GoTo BrowseError_Handling
Text2 = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, MSHFlexGrid1.Col)

If Text2.Text = rs!id Then
Image1.Picture = LoadPicture(rs!id_photo)
End If

Exit Sub

If Err = 53 Then
MsgBox "Image doesn't exist!", vbInformation, "Browse Error"
Resume Browse_Error
End If
End Sub

Note: 'id' is my students' ID field,'id_photo' is the field that stores the path to the images of the students and 'rs' is my recordset.

I assume the best way is to write a loop but frankly I am not well versed in this part of coding.

Could you please assist me in any tips or ideas that I can follow to solve this problem which has taken me almost a month now.

Thank you in advance for your time and consideration.



RE: Showing different images in one imagebox control in vb6

You don't need to pull data from your recordset. Instead, you can use the FlexGrid control to query the data (image path) directly.
Something like this...

Image1.Picture = LoadPicture(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, N))

Where N is the column number where 'id_photo' field is displayed in the FlexGrid.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close