Searching for Image and adding path

G

Guest

I am working on a database that has several records. Each record has a
different image associated with it (or will).

I will not be the only person using this database, so I want to make it very
simple to add images to records. I know that saving the image in the
database isn't the best idea for Access 2003, so instead I want to have the
path stored (which will make mail merging work too in Word).

This is what I want:
In the form, on the tab where the image information is, I want 3 things...
- The image itself displayed, once the user adds it
- The PATH of the image in a text box (so they can copy and paste into other
applications if necessary)
- A button that will allow them to browse so they can add the image. (this
button would, of course, also update the PATH and the image that is displayed.

I want both the path and the image updated when the user browses for the
image file using the browse button.

I already know that this will require at least 1 field in the table, and
that it will require some extra code...I just don't know the code.

Any help is appreciated.
 
C

Carl Rapson

Roy Carlson said:
I am working on a database that has several records. Each record has a
different image associated with it (or will).

I will not be the only person using this database, so I want to make it
very
simple to add images to records. I know that saving the image in the
database isn't the best idea for Access 2003, so instead I want to have
the
path stored (which will make mail merging work too in Word).

This is what I want:
In the form, on the tab where the image information is, I want 3 things...
- The image itself displayed, once the user adds it
- The PATH of the image in a text box (so they can copy and paste into
other
applications if necessary)
- A button that will allow them to browse so they can add the image. (this
button would, of course, also update the PATH and the image that is
displayed.

I want both the path and the image updated when the user browses for the
image file using the browse button.

I already know that this will require at least 1 field in the table, and
that it will require some extra code...I just don't know the code.

Any help is appreciated.

Yes, you will want to store the file name (with path) in the table, not the
image itself. To display an image on a form, add an Image control and set
its Picture property to the file name:

imgControl.Picture = Me.PathToFile

This is usually done in the form's Current event. Be sure to check for an
empty file name field.

To call the Windows file dialog, check out this link:

http://www.mvps.org/access/api/api0001.htm

Include that code in your application and in the browse button's Click event
call the method to display the file open/save dialog. What you'll get back
is the full path of the file, which you can then store in your field. At the
same time, use the returned path to set the image control Picture property
like above.

Carl Rapson
 
G

Guest

Is there a specific image control I should be using? I have read that using
the bound object frame is one way, but if there is a better control, I
wouldn't mind having editing capabilities on the form too.
 
C

Carl Rapson

Not sure what you mean by "editing capabilities", but I use the Image
control. I haven't worked with the object frame controls.

Carl Rapson
 
G

Guest

Well, alright. I've sort of went another route with this...sort of. The
editing thing was just a spur of the moment thing, no biggie.

I've added a "browse" button to the form which opens a window and allows me
to browse for files. (basically using the API code that is commonly refered
to in these posts).

It works, up to a point. I can browse for the image I'm looking for and
click OK. But...that's it. The code doesn't allow me to take the path and
file name and save it to the database, into a field I choose.

My hope now is that once I click OK, the code will take the path and
filename string, save it to my ImgPath field in the table, refresh the view
in the form and BINGO, the path/filename shows up in the correct box, and the
picture itself shows up in the image control.

Right now I'm using the code from mvps.org "out of the box." What else do I
need to add to it to get it to finish the job?
 
C

Carl Rapson

It's hard to say what your problem might be without seeing the actual code,
but here is what I do:

' command button: cmdBrowse
' field name in table: Picture_File
' image control name: imgToolImage
Private Sub cmdBrowse_Click()
Dim strFilter As String
Dim lngFlags As Long
Dim filename As String

' Call OpenFile dialog to locate the picture file
strFilter = ahtAddFilterItem(strFilter, "JPEG Files (*.jpg,*.jpeg)",
"*.JPG;*.JPEG")
strFilter = ahtAddFilterItem(strFilter, "GIF Files (*.gif)", "*.GIF")
strFilter = ahtAddFilterItem(strFilter, "BMP Files (*.bmp)", "*.BMP")
strFilter = ahtAddFilterItem(strFilter, "IMG Files (*.img)", "*.IMG")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
filename = ahtCommonFileOpenSave(Filter:=strFilter, FilterIndex:=5,
Flags:=lngFlags, _
DialogTitle:="Select the tool image file")
On Error Resume Next
' If the returned filename isn't blank, use it
If (Trim(Nz(filename, "")) <> "") Then
Picture_File = filename
imgToolImage.Picture = Picture_File
End If
End Sub

I'm hoping that when you say "the API code that is commonly refered to in
these posts", you mean the code from the link I posted earlier.

Carl Rapson
 
G

Guest

I went here

http://www.databasedev.co.uk/bound_image_form.html

and followed their instructions to the letter. It does EXACTLY what I want
it to do, except when I go to a record that does not have an image yet, it
displays the previous record's image. I don't like that, but I can deal with
it...unless you have a suggestion on how to fix that.
 
C

Carl Rapson

What's happening is, for records that have no ImagePath, the line

Me![ImageFrame].Picture = Me![ImagePath]

is failing, and as a result the Picture property of the ImageFrame isn't
being changed. Try this instead:

Private Sub Form_Current()
On Error Resume Next
If Not IsNull(Me![ImagePath]) Then
Me![ImageFrame].Picture = Me![ImagePath]
Else
Me![ImageFrame].Picture = ""
End If
End Sub

Private Sub ImagePath_AfterUpdate()
On Error Resume Next
If Not IsNull(Me![ImagePath]) Then
Me![ImageFrame].Picture = Me![ImagePath]
Else
Me![ImageFrame].Picture = ""
End If
End Sub

Carl Rapson
 
P

Pete

What I did was use a company logo for the default if record didn't have an
image associated with it.
Carl Rapson said:
What's happening is, for records that have no ImagePath, the line

Me![ImageFrame].Picture = Me![ImagePath]

is failing, and as a result the Picture property of the ImageFrame isn't
being changed. Try this instead:

Private Sub Form_Current()
On Error Resume Next
If Not IsNull(Me![ImagePath]) Then
Me![ImageFrame].Picture = Me![ImagePath]
Else
Me![ImageFrame].Picture = ""
End If
End Sub

Private Sub ImagePath_AfterUpdate()
On Error Resume Next
If Not IsNull(Me![ImagePath]) Then
Me![ImageFrame].Picture = Me![ImagePath]
Else
Me![ImageFrame].Picture = ""
End If
End Sub

Carl Rapson

Roy Carlson said:
I went here

http://www.databasedev.co.uk/bound_image_form.html

and followed their instructions to the letter. It does EXACTLY what I
want
it to do, except when I go to a record that does not have an image yet,
it
displays the previous record's image. I don't like that, but I can deal
with
it...unless you have a suggestion on how to fix that.
 

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