Adding an image to a form in run time

V

vinceg

I have an application which enables the user to enter the parameters of a new
project, which will help size the project and estimate a cost. As part of the
application, I want to add an image of the finished product.

I've ried every combinatin of controls: image, bound & unbound objects, but
have not found the solution.

The ideal situation would be to have a default image on the form, with a
button that would trigger code to allow the user to browse for a different
picture, and replace the original. It could be a link relationship to the
picture, but the application is not very large, so the images could be
embedded.

Any help is appreciated.

Thanks,
vinceg.
 
A

Arvin Meyer [MVP]

Use an image control. In your button's code, use:

Me.ImageControlname.Picture = "C:\PathToNew\Pic.jpg"

It's that simple.
 
V

vinceg

Arvin,
Thanks for the quick response.
The problem is I do not know the path to the image at design time.
Actually, the pictures haven't been taken yet.
I want the users to be able to click a button and have a browse dialog box
apper that will allow them to select the appropriate image to be placed in
the control.
Thanks again,
vince g
 
V

vinceg

Arvin,
Do you have any additional information on this issue, beyond
your initial response?
As I mentioned in my last post, I am looking for a way to
allow users to bring up a dialog box using a button on the form to
browse their files for the picture.
The pictures I want to add to the image control would be
retrieved from the user's file system (C:/userfolder/).
Thanks again,
 
V

vinceg

Doug,
Thank you for the response.
I'm not an expert coder......
I pasted the code into a new function from the site you mentioned,
and called the function from a command button:
"----
Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Uncomment this line to try the example
' allowing multiple file names:
' lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
If IsArray(result) Then
Dim i As Integer
For i = 0 To UBound(result)
MsgBox result(i)
Next i
Else
MsgBox result
End If
Else
MsgBox result
End If

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
-- "
Got "Sub or Function not defined" error for "ahtAddFilterItem"....

Have no idea what to do with this message.....

This may be way beyond my level of coding expertise, but I can't believe
there isn't
a run-time control that that works the same as the design time control when
you want to embed an file into an image.

I looked in MS for info on this, but don't know where to start.
I could use some help that acknowledges my relatively low level of technical
experience.
Thanks,
vinceg
 
B

BruceM via AccessMonster.com

Did you paste all of the code? ahtAddFilterItem is a function toward the
bottom of the web page link that Douglas provided. Be sure to compile the
code (Debug >> Compile) after you paste it into your code module.
Doug,
Thank you for the response.
I'm not an expert coder......
I pasted the code into a new function from the site you mentioned,
and called the function from a command button:
"----
Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Uncomment this line to try the example
' allowing multiple file names:
' lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
If IsArray(result) Then
Dim i As Integer
For i = 0 To UBound(result)
MsgBox result(i)
Next i
Else
MsgBox result
End If
Else
MsgBox result
End If

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
-- "
Got "Sub or Function not defined" error for "ahtAddFilterItem"....

Have no idea what to do with this message.....

This may be way beyond my level of coding expertise, but I can't believe
there isn't
a run-time control that that works the same as the design time control when
you want to embed an file into an image.

I looked in MS for info on this, but don't know where to start.
I could use some help that acknowledges my relatively low level of technical
experience.
Thanks,
vinceg
Use the code in http://www.mvps.org/access/api/api0001.htm at "The Access
Web" to bring up the Windows File Open dialog box to allow them to select
[quoted text clipped - 44 lines]
 
D

Douglas J. Steele

Also, make sure that the name of the module is unique: you'll run into
problems if the module has the same name as a function or sub anywhere in
the application.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BruceM via AccessMonster.com said:
Did you paste all of the code? ahtAddFilterItem is a function toward the
bottom of the web page link that Douglas provided. Be sure to compile the
code (Debug >> Compile) after you paste it into your code module.
Doug,
Thank you for the response.
I'm not an expert coder......
I pasted the code into a new function from the site you mentioned,
and called the function from a command button:
"----
Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)",
_
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Uncomment this line to try the example
' allowing multiple file names:
' lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
If IsArray(result) Then
Dim i As Integer
For i = 0 To UBound(result)
MsgBox result(i)
Next i
Else
MsgBox result
End If
Else
MsgBox result
End If

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
-- "
Got "Sub or Function not defined" error for "ahtAddFilterItem"....

Have no idea what to do with this message.....

This may be way beyond my level of coding expertise, but I can't believe
there isn't
a run-time control that that works the same as the design time control
when
you want to embed an file into an image.

I looked in MS for info on this, but don't know where to start.
I could use some help that acknowledges my relatively low level of
technical
experience.
Thanks,
vinceg
Use the code in http://www.mvps.org/access/api/api0001.htm at "The
Access
Web" to bring up the Windows File Open dialog box to allow them to
select
[quoted text clipped - 44 lines]
 
M

Max_D via AccessMonster.com

There is the component called AccessImagine, that makes inserting images in
Access database an easy task - users can browse, paste, scan or drag-n-drop
images right to database.

In fact, it can handle all the imaging tasks without any programming.
 
V

vinceg

Bruce,
Thanks for the reply.
Once I pasted all the code it workedas intended.
I got the name & path of the file I want displayed on a message box.

In the Click event Sub, I used 'result' ( the name dim'ed in the code) as
follows:
( Me.Image140.Picture = result ), and saved the form.
Pressing the button yielded the message box, but after pressing OK in the
message box, nothing appeared in the image control.
Is that the correct syntax for the image control?
I'm getting closer to understanding the way this works under the forms.
It's quite an education.... thanks.
--
vinceg


BruceM via AccessMonster.com said:
Did you paste all of the code? ahtAddFilterItem is a function toward the
bottom of the web page link that Douglas provided. Be sure to compile the
code (Debug >> Compile) after you paste it into your code module.
Doug,
Thank you for the response.
I'm not an expert coder......
I pasted the code into a new function from the site you mentioned,
and called the function from a command button:
"----
Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

' Uncomment this line to try the example
' allowing multiple file names:
' lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

Dim result As Variant

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

If lngFlags And ahtOFN_ALLOWMULTISELECT Then
If IsArray(result) Then
Dim i As Integer
For i = 0 To UBound(result)
MsgBox result(i)
Next i
Else
MsgBox result
End If
Else
MsgBox result
End If

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
-- "
Got "Sub or Function not defined" error for "ahtAddFilterItem"....

Have no idea what to do with this message.....

This may be way beyond my level of coding expertise, but I can't believe
there isn't
a run-time control that that works the same as the design time control when
you want to embed an file into an image.

I looked in MS for info on this, but don't know where to start.
I could use some help that acknowledges my relatively low level of technical
experience.
Thanks,
vinceg
Use the code in http://www.mvps.org/access/api/api0001.htm at "The Access
Web" to bring up the Windows File Open dialog box to allow them to select
[quoted text clipped - 44 lines]

--



.
 
V

vinceg

Max_D,
Thanks for the tip. I had looked at DBPix, but this looks even better.
And with my being code-challenged and all, it might be the best option for me.

Still would like to get it working thru the code, though.
Thanks again.
 
B

BruceM via AccessMonster.com

I was just offering a thought about the code you were working with. I am not
very familiar with that code, and I don't have time to investigate in detail.
You could do this after setting the value of Result:

result = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

Debug.Print result

After running the code, press Ctrl + G to open the immediate code window.
The value of result should appear there. It needs to be a path that could be
pasted into the Picture property of the image control. If you add the Debug
line and post the value that appears, it may be possible to see what has
occurred.

When I have had to insert an image, here is how I have done it. In a command
button Click event:

Dim strPhoto as String

Me.txtPhotoLink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink
strPhoto = Nz(Me.txtPhotoLink.Hyperlink.Address, "No photo")
Me.imgPhoto.PictureType = 1 ' Linked
Me.imgPhoto.Picture = strPhoto

Me.Refresh

PhotoLink is a hyperlink field in the form's Record Source table. imgPhoto
is the image control in which the photo is to appear. txtPhotoLink is a text
box, size .01 x .01, formatted the same as the background and tucked away in
a corner of the form, bound to the PhotoLink field. I think the strPhoto
line of code could be:

strPhoto = Me.txtPhotoLink.Hyperlink.Address

I may have added the Nz in case the user closed without selecting an image,
but I don't recall the details, and can't test it just now.
Bruce,
Thanks for the reply.
Once I pasted all the code it workedas intended.
I got the name & path of the file I want displayed on a message box.

In the Click event Sub, I used 'result' ( the name dim'ed in the code) as
follows:
( Me.Image140.Picture = result ), and saved the form.
Pressing the button yielded the message box, but after pressing OK in the
message box, nothing appeared in the image control.
Is that the correct syntax for the image control?
I'm getting closer to understanding the way this works under the forms.
It's quite an education.... thanks.
Did you paste all of the code? ahtAddFilterItem is a function toward the
bottom of the web page link that Douglas provided. Be sure to compile the
[quoted text clipped - 63 lines]
 
V

vinceg

To all who responded...
Thanks for your help.
The code that Doug pointed me to works perfectly,
(now that I copied all of it - DUH!)
And I figured out how to get the result from the module into
the form that holds the image.
It works like a charm, and the user is a happy camper.
This issue is closed.
Thanks again,
 

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