image path

  • Thread starter L Walsh via AccessMonster.com
  • Start date
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
 
M

MacDermott

I think you're on the right track.
You can just add
GetImagePath
in your Form_Current event procedure.

Once you've done that, you can (if you like) remove all instances of
str=GetImagePath
from your code, as they all become redundant.

What is lacking (or perhaps you just didn't post it) is a convenient way for
the user to specify an image to associate with a record.

HTH

L Walsh via AccessMonster.com said:
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
 
L

L Walsh via AccessMonster.com

Thanks, this is very helpful. I have to admit, when I tried adding the
form_current prodecure, I didn't check the form properties, and the
form_current event was set to call a macro for another purpose. So I will
have to convert the macro to VB and include it in my procedure. The picture
does display now that it calls my procedure instead of the macro. I also
discovered Access has a handy tool to convert macros to VB. I'll look into
that, as well as implementing your other suggestions.

Thanks again
LW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top