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)
rs.MoveNext
End If
Browse_Error:
Exit Sub
BrowseError_Handling:
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.
regards,
YU
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)
rs.MoveNext
End If
Browse_Error:
Exit Sub
BrowseError_Handling:
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.
regards,
YU