L
L Walsh via AccessMonster.com
I have a database of student records. On the form for the Student table, I
have an image control for a picture, and a text control for the image path.
It is supposed to display a picture of the student if there is one in a sub-
folder called Images. By default it displays a blank jpg. The problem is,
when you pull up a student record by using search binocs, it doesn't load
the student's picture. You have to click on the "previous" arrow, to the
previous record, and the the "next" arrow back to your student, and then
the picture will be loaded. I've attached the code (or what I think is the
relevant part of it) for the form.
Can you tell me how to get the picture to load when the student record is
found using the search binocs? I thought I might need a Form_Current sub,
but adding that didn't seem to work.
Here's the Code:
Private Function GetImagePath()
Dim path As String
Dim DBName As String
Dim DBStr As String
Dim str As String
DBName = CurrentDb.Name
DBStr = DBName
Do While InStr(DBStr, "\") > 0
DBStr = Right(DBStr, Len(DBStr) - InStr(DBStr, "\"))
Loop
DBName = Left(DBName, Len(DBName) - Len(DBStr) - 1)
'MsgBox DBName <- displays a box
If Len(Me!ImagePath) Then
path = Me!ImagePath
str = DBName & path
'Me![Image].Picture = Me![path]
Photo.Picture = DBName & path
Else
path = DBName & "\NoPhotoRecord.JPG"
Photo.Picture = path
' Me![Image].Picture = Me![path]
GoTo ext:
End If
ext:
End Function
Private Sub Form_Load()
Dim str As String
DoCmd.GoToRecord , , acLast
str = GetImagePath()
End Sub
Private Sub GoFirst_Click()
On Error GoTo Err_GoFirst_Click
Dim str As String
DoCmd.GoToRecord , , acFirst
str = GetImagePath()
Exit_GoFirst_Click:
Exit Sub
Err_GoFirst_Click:
MsgBox Err.Description
Resume Exit_GoFirst_Click
End Sub
Private Sub GoNext_Click()
On Error GoTo Err_GoNext_Click
Dim str As String
DoCmd.GoToRecord , , acNext
str = GetImagePath()
Exit_GoNext_Click:
Exit Sub
Err_GoNext_Click:
MsgBox Err.Description
Resume Exit_GoNext_Click
End Sub
Private Sub GoPrevious_Click()
On Error GoTo Err_GoPrevious_Click
Dim str As String
DoCmd.GoToRecord , , acPrevious
str = GetImagePath()
Exit_GoPrevious_Click:
Exit Sub
Err_GoPrevious_Click:
MsgBox Err.Description
Resume Exit_GoPrevious_Click
End Sub
Private Sub GoLAst_Click()
On Error GoTo Err_GoLAst_Click
Dim str As String
DoCmd.GoToRecord , , acLast
str = GetImagePath()
Exit_GoLAst_Click:
Exit Sub
Err_GoLAst_Click:
MsgBox Err.Description
Resume Exit_GoLAst_Click
End Sub
Private Sub Add_Click()
On Error GoTo Err_Add_Click
DoCmd.GoToRecord , , acNewRec
Exit_Add_Click:
Exit Sub
Err_Add_Click:
MsgBox Err.Description
Resume Exit_Add_Click
End Sub
tia
L.Walsh
have an image control for a picture, and a text control for the image path.
It is supposed to display a picture of the student if there is one in a sub-
folder called Images. By default it displays a blank jpg. The problem is,
when you pull up a student record by using search binocs, it doesn't load
the student's picture. You have to click on the "previous" arrow, to the
previous record, and the the "next" arrow back to your student, and then
the picture will be loaded. I've attached the code (or what I think is the
relevant part of it) for the form.
Can you tell me how to get the picture to load when the student record is
found using the search binocs? I thought I might need a Form_Current sub,
but adding that didn't seem to work.
Here's the Code:
Private Function GetImagePath()
Dim path As String
Dim DBName As String
Dim DBStr As String
Dim str As String
DBName = CurrentDb.Name
DBStr = DBName
Do While InStr(DBStr, "\") > 0
DBStr = Right(DBStr, Len(DBStr) - InStr(DBStr, "\"))
Loop
DBName = Left(DBName, Len(DBName) - Len(DBStr) - 1)
'MsgBox DBName <- displays a box
If Len(Me!ImagePath) Then
path = Me!ImagePath
str = DBName & path
'Me![Image].Picture = Me![path]
Photo.Picture = DBName & path
Else
path = DBName & "\NoPhotoRecord.JPG"
Photo.Picture = path
' Me![Image].Picture = Me![path]
GoTo ext:
End If
ext:
End Function
Private Sub Form_Load()
Dim str As String
DoCmd.GoToRecord , , acLast
str = GetImagePath()
End Sub
Private Sub GoFirst_Click()
On Error GoTo Err_GoFirst_Click
Dim str As String
DoCmd.GoToRecord , , acFirst
str = GetImagePath()
Exit_GoFirst_Click:
Exit Sub
Err_GoFirst_Click:
MsgBox Err.Description
Resume Exit_GoFirst_Click
End Sub
Private Sub GoNext_Click()
On Error GoTo Err_GoNext_Click
Dim str As String
DoCmd.GoToRecord , , acNext
str = GetImagePath()
Exit_GoNext_Click:
Exit Sub
Err_GoNext_Click:
MsgBox Err.Description
Resume Exit_GoNext_Click
End Sub
Private Sub GoPrevious_Click()
On Error GoTo Err_GoPrevious_Click
Dim str As String
DoCmd.GoToRecord , , acPrevious
str = GetImagePath()
Exit_GoPrevious_Click:
Exit Sub
Err_GoPrevious_Click:
MsgBox Err.Description
Resume Exit_GoPrevious_Click
End Sub
Private Sub GoLAst_Click()
On Error GoTo Err_GoLAst_Click
Dim str As String
DoCmd.GoToRecord , , acLast
str = GetImagePath()
Exit_GoLAst_Click:
Exit Sub
Err_GoLAst_Click:
MsgBox Err.Description
Resume Exit_GoLAst_Click
End Sub
Private Sub Add_Click()
On Error GoTo Err_Add_Click
DoCmd.GoToRecord , , acNewRec
Exit_Add_Click:
Exit Sub
Err_Add_Click:
MsgBox Err.Description
Resume Exit_Add_Click
End Sub
tia
L.Walsh