Validation of Image Path

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

I have a subform with an image on it that I'm using on the main form. Since
I'm using my flash drive {E} instead of C:\ drive, when I run the program it
keeps on telling me that the image can't be loaded/found or something like
that..

In the Picture control: C:\NCI Taps\NCI Pictures\NA.bmp
Picture type is: Linked

Is there a way where some code will check the validation of that path and
picture or some way where "On Load" the control can be set to the current
path?

Within the regular forms the picture will show up and work "On Current". This
is the code.
Me![imgEmpty].Picture = CurrentProject.Path & "\NCI Pictures\" & Me![IdPict].
Value

Because the picture form has to have some starting point, by it's self it
will not work.

Thanks for reading my post..
 
D

Douglas J. Steele

Try something like the following in your Load event:

Dim strFile As String

strFile = Mid(Forms![NameOfForm]![NameOfControl].Picture, _
InStrRev(Forms![NameOfForm]![NameOfControl].Picture, "\") + 1)

If Len(Dir(Forms![NameOfForm]![NameOfControl].Picture)) = 0 Then
If Len(Dir(CurrentProject.Path & "\" & strFile)) > 0 Then
Forms![NameOfForm]![NameOfControl].Picture = _
CurrentProject.Path & "\" & strFile
Else
Msgbox "Can't find the picture"
End If
End If
 
A

Afrosheen via AccessMonster.com

Thanks Doug for helping me out again. This is what I have

Private Sub Form_Load()
Dim strFile As String

strFile = Mid(Forms![frmpictframe]![imgEmpty].Picture, _
InStrRev(Forms![frmpictframe]![imgEmpty].Picture, "\NCI Pictures\") + 1)

If Len(Dir(Forms![frmpictframe]![imgEmpty].Picture)) = 0 Then
If Len(Dir(CurrentProject.Path & "\NCI Pictures\" & strFile)) > 0 Then
Forms![frmpictframe]![imgEmpty].Picture = _
CurrentProject.Path & "\NCI Pictures\" & strFile
Else
MsgBox "Can't find the picture"
End If
End If
End Sub

The frmpictframe is the subform.

The imgEmpty is the "picture" within the subform and it still showed C:\NCI
Taps\NCI Pictures\NA.bmp. after I ran the code. I tried to delete the picture
control but it kept coming back

I ran the code and still got the error. After I clicked ok then it seemed to
work

I did do a ?strFile and it did show the correct file name: NA.Bmp

I did change this with the NCI Pictures. CurrentProject.Path & "\NCI Pictures\
" & strFile

Every record has a picture field like NA.bmp, fred.jpg and so on. There are
pictures in the NCI Pictures folder. When I set up the subform with the
picture of course it wants a place where pictures are located. At that time
and when I use the C drive I don't have a problem. Now that I'm using the
flash drive and other drives in the future there's going to be a problem.



Try something like the following in your Load event:

Dim strFile As String

strFile = Mid(Forms![NameOfForm]![NameOfControl].Picture, _
InStrRev(Forms![NameOfForm]![NameOfControl].Picture, "\") + 1)

If Len(Dir(Forms![NameOfForm]![NameOfControl].Picture)) = 0 Then
If Len(Dir(CurrentProject.Path & "\" & strFile)) > 0 Then
Forms![NameOfForm]![NameOfControl].Picture = _
CurrentProject.Path & "\" & strFile
Else
Msgbox "Can't find the picture"
End If
End If
I have a subform with an image on it that I'm using on the main form. Since
I'm using my flash drive {E} instead of C:\ drive, when I run the program
[quoted text clipped - 20 lines]
Thanks for reading my post..
 
D

Douglas J. Steele

Subform? If you're dealing with a subform, you need to go through the parent
form. See http://www.mvps.org/access/forms/frm0031.htm at "The Access Web"
for how to refer controls on subforms.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

Afrosheen via AccessMonster.com said:
Thanks Doug for helping me out again. This is what I have

Private Sub Form_Load()
Dim strFile As String

strFile = Mid(Forms![frmpictframe]![imgEmpty].Picture, _
InStrRev(Forms![frmpictframe]![imgEmpty].Picture, "\NCI Pictures\") + 1)

If Len(Dir(Forms![frmpictframe]![imgEmpty].Picture)) = 0 Then
If Len(Dir(CurrentProject.Path & "\NCI Pictures\" & strFile)) > 0 Then
Forms![frmpictframe]![imgEmpty].Picture = _
CurrentProject.Path & "\NCI Pictures\" & strFile
Else
MsgBox "Can't find the picture"
End If
End If
End Sub

The frmpictframe is the subform.

The imgEmpty is the "picture" within the subform and it still showed
C:\NCI
Taps\NCI Pictures\NA.bmp. after I ran the code. I tried to delete the
picture
control but it kept coming back

I ran the code and still got the error. After I clicked ok then it seemed
to
work

I did do a ?strFile and it did show the correct file name: NA.Bmp

I did change this with the NCI Pictures. CurrentProject.Path & "\NCI
Pictures\
" & strFile

Every record has a picture field like NA.bmp, fred.jpg and so on. There
are
pictures in the NCI Pictures folder. When I set up the subform with the
picture of course it wants a place where pictures are located. At that
time
and when I use the C drive I don't have a problem. Now that I'm using the
flash drive and other drives in the future there's going to be a problem.



Try something like the following in your Load event:

Dim strFile As String

strFile = Mid(Forms![NameOfForm]![NameOfControl].Picture, _
InStrRev(Forms![NameOfForm]![NameOfControl].Picture, "\") + 1)

If Len(Dir(Forms![NameOfForm]![NameOfControl].Picture)) = 0 Then
If Len(Dir(CurrentProject.Path & "\" & strFile)) > 0 Then
Forms![NameOfForm]![NameOfControl].Picture = _
CurrentProject.Path & "\" & strFile
Else
Msgbox "Can't find the picture"
End If
End If
I have a subform with an image on it that I'm using on the main form.
Since
I'm using my flash drive {E} instead of C:\ drive, when I run the
program
[quoted text clipped - 20 lines]
Thanks for reading my post..
 

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