Adding an image to a form in run time

  • Thread starter Thread starter vinceg
  • Start date Start date
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.
 
Use an image control. In your button's code, use:

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

It's that simple.
 
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
 
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,
 
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
 
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]
 
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]

--
Message posted via AccessMonster.com


.
 
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.
 
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,
 
Back
Top