G
Guest
Hi! Does anyone know how to convert JPEGs into bitmaps to enable linking in
access? Many thanks
access? Many thanks
Jo said:Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an image,
then
I cleared the filename in the picture property and am left with a greyed
frame in design view and nothing in the form view.
I have added a text box and in the source perperties have navigated to my
table containing personphoto. =[Table1]![personphoto].
In the text box properties, Event, After Update I have typed in the code:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub personphoto_AfterUpdate()
End Sub
The 'hide image control if no picture is in green ?
When I go to form view the text box has #Name?
Basically nothing much is happening! What have I missed out?
Don't give up on me yet!!
Rob Parker said:Hi Jo,
Help is what we're here for ;-)
First off, don't even think about actually storing the images within the
database, as OLE objects. Although you can do this, it is very
inefficient
and leads to rapid database bloat (eg. a few days ago I did a test, with
a
150kb image; this increased the database size by about 4MB!). There are
several ways of dealing with images in a database, as described in
previous
posts by MVP Larry Linson, thus:
<quote>
The sample imaging databases at http://accdevel.tripod.com illustrate
three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat,
and
some other problems, associated with images in OLE Objects. (Note: Access
2007 has eliminated the bloat problem, but you still are using external
software and are subject to its featuree, funcions, and foibles.)
If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans'
http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer
Driver.
This MDB also contains code showing how to convert the contents of the
Image
control to a Bitmap file prior to printing. This helps alleviate the "Out
of
Memory" error that can popup when printing image intensive reports.
Larry Linson
Microsoft Access MVP
<end quote>
The approach that I use is to store the image path/filename in a field,
and
use an Image control on a form (or report) to display the image
associated
with each record. It requires a little bit of VBA code in the form's
Current event (or the Format event of the report section contining the
image
control). Here's the nitty-gritty of how to do it.
Store the image path/filename in a field; I'll call it PersonPhoto. You
can
store either just the filename, or the full path/filename (see below for
details of what changes). Place an Image control in your form (or
report)
to display the picture. You will probably be asked to select a picture
when
you create the image control; pick any image file, and after the image
control has been created remove the entry from the Picture property of
the
image control. I suggest also setting the Size Mode to Zoom; this will
make
the pictures resize to fit the control (while retaining their aspect
ratio).
Set the name of this image control to imgPersonPhoto. Also add a textbox
control bound to the PersonPhoto field; you can set the visible property
of
the textbox to No if you don't want to see it, or you can leave it
visible
to allow the image to be changed (if you do that, you'll need to place a
copy of the code below in the AfterUpdate event of the textbox so that
the
image changes when you change the entry).
You then need some simple VBA code in the Current event of the form (or
the
Format event of the section of the report) to display the picture
associated
with the current record. If your PersonPhoto field contains the full
path/filename for each picture, all you should need is:
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
If you are only storing the filename of the image, then you will need to
include the full pathname to the folder where the images are stored in
your
code, and include it in the expression which sets the .Picture property
of
the image control. Something like this will work:
Dim strPath as String
strPath = "C:\Documents and Settings\UserName\My
Documents\ImageFolder\"
' change the text string above to your actual pathname, including the
trailing slash
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = strPath & Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
To prevent Access from crashing when scrolling/paging rapidly through any
form/report containing images, you need to modify some registry keys.
The
details are available at
http://www.mvps.org/access/downloads/Set_ShowProgressDialog_To_No.reg
The easy way to incorporate these is this: Cut/paste to a text file (I
used
Notepad), and save as a .reg file. Then all you need do is double-click
the
file, or right-click and choose "Merge", to merge the entries into your
registry. For a 19kb file of entries, that's certainly faster than
entering them all manually ;-) Note: there are more entries here than
are
actually needed to solve the problem, but it's so easy to import the lot
that it's not worth figuring out exactly which ones you need.
HTH,
Rob
Rob Parker said:Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the other
side of the world! This post of yours was at 10:14 PM (after I closed down
on Saturday night), with your subsequent post (a follow-up with essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is incorrect,
and that is giving you the #Name? error. The Control Source for the textbox
should simply be [personphoto] (the square brackets are not necessary if the
field name does not contain any spaces); and the form's Record Source must
be the table containing the personphoto field (or a query based on that
table).
The code as you posted it will not run, because the actual code is not in
the event handler (the Sub personphoto_AfterUpdate() ). The code I posted
must go between the "stub" which is generated when you click on the ...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since it's a
bound control, the content of the field in the table for the current record)
is changed. As I said, you need it if you want to use the textbox as a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it in
your form when the form opens, or when you move to a different record, you
need this same code in the Current event of the form itself. You need to
have an Event Procedure for the form's Current event, and it will look like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will possibly
(probably) find that it is not attached to the form's current event. You
must have [Event Procedure] in the current event of the form's property
sheet.
If you want to use the same technique in a report, you need to put the code
into the Format event of the section of the report where the image control
is located.
And finally, the line which appears in green is a comment line, rather than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a double-quoted
text string) is considered to be a comment. Including comments is a useful
way of documenting what your code is (supposed to be) doing. You can have a
complete line as a comment (as in the sample I posted), or you can include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no picture
HTH, and please post again if you're still having problems (but remember
that we're out-of-sync with our times),
Rob
Jo said:Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an image,
then
I cleared the filename in the picture property and am left with a greyed
frame in design view and nothing in the form view.
I have added a text box and in the source perperties have navigated to my
table containing personphoto. =[Table1]![personphoto].
In the text box properties, Event, After Update I have typed in the code:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub personphoto_AfterUpdate()
End Sub
The 'hide image control if no picture is in green ?
When I go to form view the text box has #Name?
Basically nothing much is happening! What have I missed out?
Don't give up on me yet!!
Rob Parker said:Hi Jo,
Help is what we're here for ;-)
First off, don't even think about actually storing the images within the
database, as OLE objects. Although you can do this, it is very
inefficient
and leads to rapid database bloat (eg. a few days ago I did a test, with
a
150kb image; this increased the database size by about 4MB!). There are
several ways of dealing with images in a database, as described in
previous
posts by MVP Larry Linson, thus:
<quote>
The sample imaging databases at http://accdevel.tripod.com illustrate
three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat,
and
some other problems, associated with images in OLE Objects. (Note: Access
2007 has eliminated the bloat problem, but you still are using external
software and are subject to its featuree, funcions, and foibles.)
If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans'
http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer
Driver.
This MDB also contains code showing how to convert the contents of the
Image
control to a Bitmap file prior to printing. This helps alleviate the "Out
of
Memory" error that can popup when printing image intensive reports.
Larry Linson
Microsoft Access MVP
<end quote>
The approach that I use is to store the image path/filename in a field,
and
use an Image control on a form (or report) to display the image
associated
with each record. It requires a little bit of VBA code in the form's
Current event (or the Format event of the report section contining the
image
control). Here's the nitty-gritty of how to do it.
Store the image path/filename in a field; I'll call it PersonPhoto. You
can
store either just the filename, or the full path/filename (see below for
details of what changes). Place an Image control in your form (or
report)
to display the picture. You will probably be asked to select a picture
when
you create the image control; pick any image file, and after the image
control has been created remove the entry from the Picture property of
the
image control. I suggest also setting the Size Mode to Zoom; this will
make
the pictures resize to fit the control (while retaining their aspect
ratio).
Set the name of this image control to imgPersonPhoto. Also add a textbox
control bound to the PersonPhoto field; you can set the visible property
of
the textbox to No if you don't want to see it, or you can leave it
visible
to allow the image to be changed (if you do that, you'll need to place a
copy of the code below in the AfterUpdate event of the textbox so that
the
image changes when you change the entry).
You then need some simple VBA code in the Current event of the form (or
the
Format event of the section of the report) to display the picture
associated
with the current record. If your PersonPhoto field contains the full
path/filename for each picture, all you should need is:
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
If you are only storing the filename of the image, then you will need to
include the full pathname to the folder where the images are stored in
your
code, and include it in the expression which sets the .Picture property
of
the image control. Something like this will work:
Dim strPath as String
strPath = "C:\Documents and Settings\UserName\My
Documents\ImageFolder\"
' change the text string above to your actual pathname, including the
trailing slash
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = strPath & Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
To prevent Access from crashing when scrolling/paging rapidly through any
form/report containing images, you need to modify some registry keys.
The
details are available at
http://www.mvps.org/access/downloads/Set_ShowProgressDialog_To_No.reg
The easy way to incorporate these is this: Cut/paste to a text file (I
used
Notepad), and save as a .reg file. Then all you need do is double-click
the
file, or right-click and choose "Merge", to merge the entries into your
registry. For a 19kb file of entries, that's certainly faster than
entering them all manually ;-) Note: there are more entries here than
are
actually needed to solve the problem, but it's so easy to import the lot
that it's not worth figuring out exactly which ones you need.
HTH,
Rob
Hi Rob,
I am very confused now - it doesn't take much! I have photos of people
saved as jpegs. I have a table with these people's contact details in.
I
want to link the photo to the person to show on forms or reports. In
Access
the help says you can have photos embedded in an OLE field - but they
have
to
be either bitmaps or Device Independent Bitmap (.dib) graphic file
formats.
Please help me!
:
Hey Jo (apologies to Jimi),
I'm not sure what you mean by "attached", but Access (from personal
experience with every version from A97 to A2003 - and I would bet that
it
hasn't changed with A2007) can cope perfectly well with jpeg files as
the
source for the Picture property in an image control.
Or as the content of an OLE object directly in a table - but nobody
who
understands how Access (mis)handles such objects would do this; it
leads
to
uncontrollable database bloat. Browse these newsgroups for
questions -
and
solutions - about this problem.
What are you trying to do that you leads you to think that you need to
convert to bitmap, or buy extra software?
Rob
because access won't allow jpegs to be attached unless you buy extra
software.
:
Why do you need to convert JPEG into Bitmap?
--
Jo said:Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I click
on
the image and properties, Event, On Click ... I have the following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression On
Current you entered as the event property setting produced the following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
Rob Parker said:Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the
other
side of the world! This post of yours was at 10:14 PM (after I closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for the
textbox
should simply be [personphoto] (the square brackets are not necessary if
the
field name does not contain any spaces); and the form's Record Source
must
be the table containing the personphoto field (or a query based on that
table).
The code as you posted it will not run, because the actual code is not in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the ...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since it's
a
bound control, the content of the field in the table for the current
record)
is changed. As I said, you need it if you want to use the textbox as a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it in
your form when the form opens, or when you move to a different record,
you
need this same code in the Current event of the form itself. You need to
have an Event Procedure for the form's Current event, and it will look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will possibly
(probably) find that it is not attached to the form's current event. You
must have [Event Procedure] in the current event of the form's property
sheet.
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line, rather
than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a double-quoted
text string) is considered to be a comment. Including comments is a
useful
way of documenting what your code is (supposed to be) doing. You can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no picture
HTH, and please post again if you're still having problems (but remember
that we're out-of-sync with our times),
Rob
Jo said:Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an image,
then
I cleared the filename in the picture property and am left with a
greyed
frame in design view and nothing in the form view.
I have added a text box and in the source perperties have navigated to
my
table containing personphoto. =[Table1]![personphoto].
In the text box properties, Event, After Update I have typed in the
code:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub personphoto_AfterUpdate()
End Sub
The 'hide image control if no picture is in green ?
When I go to form view the text box has #Name?
Basically nothing much is happening! What have I missed out?
Don't give up on me yet!!
:
Hi Jo,
Help is what we're here for ;-)
First off, don't even think about actually storing the images within
the
database, as OLE objects. Although you can do this, it is very
inefficient
and leads to rapid database bloat (eg. a few days ago I did a test,
with
a
150kb image; this increased the database size by about 4MB!). There
are
several ways of dealing with images in a database, as described in
previous
posts by MVP Larry Linson, thus:
<quote>
The sample imaging databases at http://accdevel.tripod.com illustrate
three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat,
and
some other problems, associated with images in OLE Objects. (Note:
Access
2007 has eliminated the bloat problem, but you still are using
external
software and are subject to its featuree, funcions, and foibles.)
If you are printing the images in reports, to avoid memory leakage,
you
should also see MVP Stephen Lebans'
http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails
during
the Access formatting process prior to being spooled to the Printer
Driver.
This MDB also contains code showing how to convert the contents of the
Image
control to a Bitmap file prior to printing. This helps alleviate the
"Out
of
Memory" error that can popup when printing image intensive reports.
Larry Linson
Microsoft Access MVP
<end quote>
The approach that I use is to store the image path/filename in a
field,
and
use an Image control on a form (or report) to display the image
associated
with each record. It requires a little bit of VBA code in the form's
Current event (or the Format event of the report section contining the
image
control). Here's the nitty-gritty of how to do it.
Store the image path/filename in a field; I'll call it PersonPhoto.
You
can
store either just the filename, or the full path/filename (see below
for
details of what changes). Place an Image control in your form (or
report)
to display the picture. You will probably be asked to select a
picture
when
you create the image control; pick any image file, and after the image
control has been created remove the entry from the Picture property of
the
image control. I suggest also setting the Size Mode to Zoom; this
will
make
the pictures resize to fit the control (while retaining their aspect
ratio).
Set the name of this image control to imgPersonPhoto. Also add a
textbox
control bound to the PersonPhoto field; you can set the visible
property
of
the textbox to No if you don't want to see it, or you can leave it
visible
to allow the image to be changed (if you do that, you'll need to place
a
copy of the code below in the AfterUpdate event of the textbox so that
the
image changes when you change the entry).
You then need some simple VBA code in the Current event of the form
(or
the
Format event of the section of the report) to display the picture
associated
with the current record. If your PersonPhoto field contains the full
path/filename for each picture, all you should need is:
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
If you are only storing the filename of the image, then you will need
to
include the full pathname to the folder where the images are stored in
your
code, and include it in the expression which sets the .Picture
property
of
the image control. Something like this will work:
Dim strPath as String
strPath = "C:\Documents and Settings\UserName\My
Documents\ImageFolder\"
' change the text string above to your actual pathname, including the
trailing slash
If Not IsNull(Me.PersonPhoto) Then
Me.imgPersonPhoto.Picture = strPath & Me.PersonPhoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
To prevent Access from crashing when scrolling/paging rapidly through
any
form/report containing images, you need to modify some registry keys.
The
details are available at
http://www.mvps.org/access/downloads/Set_ShowProgressDialog_To_No.reg
The easy way to incorporate these is this: Cut/paste to a text file
(I
used
Notepad), and save as a .reg file. Then all you need do is
double-click
the
file, or right-click and choose "Merge", to merge the entries into
your
registry. For a 19kb file of entries, that's certainly faster than
entering them all manually ;-) Note: there are more entries here than
are
actually needed to solve the problem, but it's so easy to import the
lot
that it's not worth figuring out exactly which ones you need.
HTH,
Rob
Hi Rob,
I am very confused now - it doesn't take much! I have photos of
people
saved as jpegs. I have a table with these people's contact details
in.
I
want to link the photo to the person to show on forms or reports.
In
Access
the help says you can have photos embedded in an OLE field - but
they
have
to
be either bitmaps or Device Independent Bitmap (.dib) graphic file
formats.
Please help me!
:
Hey Jo (apologies to Jimi),
I'm not sure what you mean by "attached", but Access (from personal
experience with every version from A97 to A2003 - and I would bet
that
it
hasn't changed with A2007) can cope perfectly well with jpeg files
as
the
source for the Picture property in an image control.
Or as the content of an OLE object directly in a table - but nobody
who
understands how Access (mis)handles such objects would do this; it
leads
to
uncontrollable database bloat. Browse these newsgroups for
questions -
and
solutions - about this problem.
What are you trying to do that you leads you to think that you need
to
convert to bitmap, or buy extra software?
Rob
because access won't allow jpegs to be attached unless you buy
extra
software.
:
Why do you need to convert JPEG into Bitmap?
--
Rob Parker said:Hi Jo,
Sorry that this will be a very quick response, but now I'm away until next
weekend, with only occassional (very slow dial-up) access.
What you've done seems to be right in most regards, except that I'm a little
confused about exactly what code you have attached to what events; and more
importantly, it seems that you have some "floating" code that is not
attached to any event. You should have code in the Form_Current event and
the PersonPhoto_AfterUpdate event (assuming that the textbox control bound
to the personphoto field from your query is also named "personphoto"). You
should NOT have any code in the code module for the form which does not
appear between a pair of "Private Sub ..." and "End Sub" statements.
You do not need any code in the Click event of the imagecontrol itself; the
code in the form's Current event deals with changing the image as you move
between records (or open the form). The code in the textbox control's
AfterUpdate event deals with changing the image if you change the
path/filename entry for the image.
Could you check that these details are correct, and also please post the SQL
view of the query which is your form's datasource. Also check that the
image control is named imgPersonPhoto.
I'll get back to you again as soon as possible, but it may be a couple of
days.
Rob
Jo said:Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I click
on
the image and properties, Event, On Click ... I have the following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression On
Current you entered as the event property setting produced the following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
Rob Parker said:Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the
other
side of the world! This post of yours was at 10:14 PM (after I closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for the
textbox
should simply be [personphoto] (the square brackets are not necessary if
the
field name does not contain any spaces); and the form's Record Source
must
be the table containing the personphoto field (or a query based on that
table).
The code as you posted it will not run, because the actual code is not in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the ...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since it's
a
bound control, the content of the field in the table for the current
record)
is changed. As I said, you need it if you want to use the textbox as a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it in
your form when the form opens, or when you move to a different record,
you
need this same code in the Current event of the form itself. You need to
have an Event Procedure for the form's Current event, and it will look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will possibly
(probably) find that it is not attached to the form's current event. You
must have [Event Procedure] in the current event of the form's property
sheet.
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line, rather
than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a double-quoted
text string) is considered to be a comment. Including comments is a
useful
way of documenting what your code is (supposed to be) doing. You can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no picture
HTH, and please post again if you're still having problems (but remember
that we're out-of-sync with our times),
Rob
Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an image,
then
I cleared the filename in the picture property and am left with a
greyed
frame in design view and nothing in the form view.
I have added a text box and in the source perperties have navigated to
my
table containing personphoto. =[Table1]![personphoto].
In the text box properties, Event, After Update I have typed in the
code:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub personphoto_AfterUpdate()
End Sub
The 'hide image control if no picture is in green ?
When I go to form view the text box has #Name?
Basically nothing much is happening! What have I missed out?
Don't give up on me yet!!
:
Hi Jo,
Help is what we're here for ;-)
First off, don't even think about actually storing the images within
the
database, as OLE objects. Although you can do this, it is very
inefficient
and leads to rapid database bloat (eg. a few days ago I did a test,
with
a
150kb image; this increased the database size by about 4MB!). There
are
several ways of dealing with images in a database, as described in
previous
posts by MVP Larry Linson, thus:
<quote>
The sample imaging databases at http://accdevel.tripod.com illustrate
three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat,
and
some other problems, associated with images in OLE Objects. (Note:
Access
2007 has eliminated the bloat problem, but you still are using
external
software and are subject to its featuree, funcions, and foibles.)
If you are printing the images in reports, to avoid memory leakage,
you
should also see MVP Stephen Lebans'
Jo said:HI Rob, Fantastic my form now works! Thanks a lot.
Now I want my report to work....
Have set up a report with the fields from my query.
Have added an image control, browsed and then eleted the path name.
Have added a text box and set te control to the PersonPhoto field.
When I go into the properties of this field there is a blank tab for
Events.
Therfore I don't know where to put the code!
Help please! So nearly there!
Jo
Rob Parker said:Hi Jo,
Sorry that this will be a very quick response, but now I'm away until
next
weekend, with only occassional (very slow dial-up) access.
What you've done seems to be right in most regards, except that I'm a
little
confused about exactly what code you have attached to what events; and
more
importantly, it seems that you have some "floating" code that is not
attached to any event. You should have code in the Form_Current event
and
the PersonPhoto_AfterUpdate event (assuming that the textbox control
bound
to the personphoto field from your query is also named "personphoto").
You
should NOT have any code in the code module for the form which does not
appear between a pair of "Private Sub ..." and "End Sub" statements.
You do not need any code in the Click event of the imagecontrol itself;
the
code in the form's Current event deals with changing the image as you
move
between records (or open the form). The code in the textbox control's
AfterUpdate event deals with changing the image if you change the
path/filename entry for the image.
Could you check that these details are correct, and also please post the
SQL
view of the query which is your form's datasource. Also check that the
image control is named imgPersonPhoto.
I'll get back to you again as soon as possible, but it may be a couple of
days.
Rob
Jo said:Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each
record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I
click
on
the image and properties, Event, On Click ... I have the following
VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression On
Current you entered as the event property setting produced the
following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
:
Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the
other
side of the world! This post of yours was at 10:14 PM (after I closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for the
textbox
should simply be [personphoto] (the square brackets are not necessary
if
the
field name does not contain any spaces); and the form's Record Source
must
be the table containing the personphoto field (or a query based on
that
table).
The code as you posted it will not run, because the actual code is not
in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the
...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since
it's
a
bound control, the content of the field in the table for the current
record)
is changed. As I said, you need it if you want to use the textbox as
a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it
in
your form when the form opens, or when you move to a different record,
you
need this same code in the Current event of the form itself. You need
to
have an Event Procedure for the form's Current event, and it will look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will
possibly
(probably) find that it is not attached to the form's current event.
You
must have [Event Procedure] in the current event of the form's
property
sheet.
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line, rather
than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a
double-quoted
text string) is considered to be a comment. Including comments is a
useful
way of documenting what your code is (supposed to be) doing. You can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no
picture
HTH, and please post again if you're still having problems (but
remember
that we're out-of-sync with our times),
Rob
Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an
image,
then
I cleared the filename in the picture property and am left with a
greyed
frame in design view and nothing in the form view.
I have added a text box and in the source perperties have navigated
to
my
table containing personphoto. =[Table1]![personphoto].
In the text box properties, Event, After Update I have typed in the
code:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub personphoto_AfterUpdate()
End Sub
The 'hide image control if no picture is in green ?
When I go to form view the text box has #Name?
Basically nothing much is happening! What have I missed out?
Don't give up on me yet!!
:
Hi Jo,
Help is what we're here for ;-)
First off, don't even think about actually storing the images
within
the
database, as OLE objects. Although you can do this, it is very
inefficient
and leads to rapid database bloat (eg. a few days ago I did a test,
with
a
150kb image; this increased the database size by about 4MB!).
There
are
several ways of dealing with images in a database, as described in
previous
posts by MVP Larry Linson, thus:
<quote>
The sample imaging databases at http://accdevel.tripod.com
illustrate
three
approaches to handling images in Access, and the download includes
an
article discussing considerations in choosing an approach. Two of
the
approaches do not use OLE Objects and, thus, avoid the database
bloat,
and
some other problems, associated with images in OLE Objects. (Note:
Access
2007 has eliminated the bloat problem, but you still are using
external
software and are subject to its featuree, funcions, and foibles.)
If you are printing the images in reports, to avoid memory leakage,
you
should also see MVP Stephen Lebans'
Rob Parker said:Hi Jo,
In either my first or second post to you, I covered this point:
<quote>
If you want to use the same technique in a report, you need to put the code
into the Format event of the section of the report where the image control
is located.
<end quote>
So, select the report section which contains the image control (the easiest
way is to click in the bar at the top of the section), and choose the On
Format event. Enter/select Event Procedure for this property, and put the
code between the
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
and
End Sub
statements that appear in the VBA editor. If your image control is not in
the Detail section, the Private Sub ... line will contain the name of the
section you have chosen, rather than Detail.
Don't forget the registry entries modifications I mentioned in that same
earlier post, to avoid possible crashes when previewing/printing the report.
Rob
Jo said:HI Rob, Fantastic my form now works! Thanks a lot.
Now I want my report to work....
Have set up a report with the fields from my query.
Have added an image control, browsed and then eleted the path name.
Have added a text box and set te control to the PersonPhoto field.
When I go into the properties of this field there is a blank tab for
Events.
Therfore I don't know where to put the code!
Help please! So nearly there!
Jo
Rob Parker said:Hi Jo,
Sorry that this will be a very quick response, but now I'm away until
next
weekend, with only occassional (very slow dial-up) access.
What you've done seems to be right in most regards, except that I'm a
little
confused about exactly what code you have attached to what events; and
more
importantly, it seems that you have some "floating" code that is not
attached to any event. You should have code in the Form_Current event
and
the PersonPhoto_AfterUpdate event (assuming that the textbox control
bound
to the personphoto field from your query is also named "personphoto").
You
should NOT have any code in the code module for the form which does not
appear between a pair of "Private Sub ..." and "End Sub" statements.
You do not need any code in the Click event of the imagecontrol itself;
the
code in the form's Current event deals with changing the image as you
move
between records (or open the form). The code in the textbox control's
AfterUpdate event deals with changing the image if you change the
path/filename entry for the image.
Could you check that these details are correct, and also please post the
SQL
view of the query which is your form's datasource. Also check that the
image control is named imgPersonPhoto.
I'll get back to you again as soon as possible, but it may be a couple of
days.
Rob
Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each
record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I
click
on
the image and properties, Event, On Click ... I have the following
VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression On
Current you entered as the event property setting produced the
following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
:
Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the
other
side of the world! This post of yours was at 10:14 PM (after I closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for the
textbox
should simply be [personphoto] (the square brackets are not necessary
if
the
field name does not contain any spaces); and the form's Record Source
must
be the table containing the personphoto field (or a query based on
that
table).
The code as you posted it will not run, because the actual code is not
in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the
...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since
it's
a
bound control, the content of the field in the table for the current
record)
is changed. As I said, you need it if you want to use the textbox as
a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it
in
your form when the form opens, or when you move to a different record,
you
need this same code in the Current event of the form itself. You need
to
have an Event Procedure for the form's Current event, and it will look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will
possibly
(probably) find that it is not attached to the form's current event.
You
must have [Event Procedure] in the current event of the form's
property
sheet.
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line, rather
than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a
double-quoted
text string) is considered to be a comment. Including comments is a
useful
way of documenting what your code is (supposed to be) doing. You can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no
picture
HTH, and please post again if you're still having problems (but
remember
that we're out-of-sync with our times),
Rob
Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an
Rob Parker said:Hi Jo,
In either my first or second post to you, I covered this point:
<quote>
If you want to use the same technique in a report, you need to put the code
into the Format event of the section of the report where the image control
is located.
<end quote>
So, select the report section which contains the image control (the easiest
way is to click in the bar at the top of the section), and choose the On
Format event. Enter/select Event Procedure for this property, and put the
code between the
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
and
End Sub
statements that appear in the VBA editor. If your image control is not in
the Detail section, the Private Sub ... line will contain the name of the
section you have chosen, rather than Detail.
Don't forget the registry entries modifications I mentioned in that same
earlier post, to avoid possible crashes when previewing/printing the report.
Rob
Jo said:HI Rob, Fantastic my form now works! Thanks a lot.
Now I want my report to work....
Have set up a report with the fields from my query.
Have added an image control, browsed and then eleted the path name.
Have added a text box and set te control to the PersonPhoto field.
When I go into the properties of this field there is a blank tab for
Events.
Therfore I don't know where to put the code!
Help please! So nearly there!
Jo
Rob Parker said:Hi Jo,
Sorry that this will be a very quick response, but now I'm away until
next
weekend, with only occassional (very slow dial-up) access.
What you've done seems to be right in most regards, except that I'm a
little
confused about exactly what code you have attached to what events; and
more
importantly, it seems that you have some "floating" code that is not
attached to any event. You should have code in the Form_Current event
and
the PersonPhoto_AfterUpdate event (assuming that the textbox control
bound
to the personphoto field from your query is also named "personphoto").
You
should NOT have any code in the code module for the form which does not
appear between a pair of "Private Sub ..." and "End Sub" statements.
You do not need any code in the Click event of the imagecontrol itself;
the
code in the form's Current event deals with changing the image as you
move
between records (or open the form). The code in the textbox control's
AfterUpdate event deals with changing the image if you change the
path/filename entry for the image.
Could you check that these details are correct, and also please post the
SQL
view of the query which is your form's datasource. Also check that the
image control is named imgPersonPhoto.
I'll get back to you again as soon as possible, but it may be a couple of
days.
Rob
Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each
record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I
click
on
the image and properties, Event, On Click ... I have the following
VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression On
Current you entered as the event property setting produced the
following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
:
Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on the
other
side of the world! This post of yours was at 10:14 PM (after I closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you ;-)
You're on the right track, but missing a couple of important points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for the
textbox
should simply be [personphoto] (the square brackets are not necessary
if
the
field name does not contain any spaces); and the form's Record Source
must
be the table containing the personphoto field (or a query based on
that
table).
The code as you posted it will not run, because the actual code is not
in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the
...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since
it's
a
bound control, the content of the field in the table for the current
record)
is changed. As I said, you need it if you want to use the textbox as
a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display it
in
your form when the form opens, or when you move to a different record,
you
need this same code in the Current event of the form itself. You need
to
have an Event Procedure for the form's Current event, and it will look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will
possibly
(probably) find that it is not attached to the form's current event.
You
must have [Event Procedure] in the current event of the form's
property
sheet.
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line, rather
than
executable code. in the VBA editor, anything following a single-quote
character (except where the single-quote is contained in a
double-quoted
text string) is considered to be a comment. Including comments is a
useful
way of documenting what your code is (supposed to be) doing. You can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no
picture
HTH, and please post again if you're still having problems (but
remember
that we're out-of-sync with our times),
Rob
Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an
Jo said:Hi Rob.
Fantastic. The report and Form are now working beautifully.
One last thing - I have had a look at he Stephen Labans website but not
sure
exactly what I need to download about the Registrationmodification and
also
where to copy it to.
Also, It talks about converting the jpegs to bitmaps before printing - do
I
need to do this or is this part of it?
Thanks so much
Jo
Rob Parker said:Hi Jo,
In either my first or second post to you, I covered this point:
<quote>
If you want to use the same technique in a report, you need to put the
code
into the Format event of the section of the report where the image
control
is located.
<end quote>
So, select the report section which contains the image control (the
easiest
way is to click in the bar at the top of the section), and choose the On
Format event. Enter/select Event Procedure for this property, and put
the
code between the
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
and
End Sub
statements that appear in the VBA editor. If your image control is not
in
the Detail section, the Private Sub ... line will contain the name of the
section you have chosen, rather than Detail.
Don't forget the registry entries modifications I mentioned in that same
earlier post, to avoid possible crashes when previewing/printing the
report.
Rob
Jo said:HI Rob, Fantastic my form now works! Thanks a lot.
Now I want my report to work....
Have set up a report with the fields from my query.
Have added an image control, browsed and then eleted the path name.
Have added a text box and set te control to the PersonPhoto field.
When I go into the properties of this field there is a blank tab for
Events.
Therfore I don't know where to put the code!
Help please! So nearly there!
Jo
:
Hi Jo,
Sorry that this will be a very quick response, but now I'm away until
next
weekend, with only occassional (very slow dial-up) access.
What you've done seems to be right in most regards, except that I'm a
little
confused about exactly what code you have attached to what events; and
more
importantly, it seems that you have some "floating" code that is not
attached to any event. You should have code in the Form_Current event
and
the PersonPhoto_AfterUpdate event (assuming that the textbox control
bound
to the personphoto field from your query is also named "personphoto").
You
should NOT have any code in the code module for the form which does
not
appear between a pair of "Private Sub ..." and "End Sub" statements.
You do not need any code in the Click event of the imagecontrol
itself;
the
code in the form's Current event deals with changing the image as you
move
between records (or open the form). The code in the textbox control's
AfterUpdate event deals with changing the image if you change the
path/filename entry for the image.
Could you check that these details are correct, and also please post
the
SQL
view of the query which is your form's datasource. Also check that
the
image control is named imgPersonPhoto.
I'll get back to you again as soon as possible, but it may be a couple
of
days.
Rob
Hi Rob, Delayed response as have been on a training course.
I am closer but still not there yet.
I have my form and the DataSource is a query linking my two tables.
Table1 has 2 fields: ID (text); PersonPhoto (text) I have typed in
the
comlete path and filename.jpg in here. Should it be text field?
Table2 has personal details fields and ID.
Query1 links on ID and has all the fields in.
Form1 has Query1 as it's datasource and I can scroll through each
record -
except the photo as this is still not working!
To recap. I inserted an image, name imgPersonPhoto; browsed for the
picture
then cut the path out. Picture type? should this be linked? When I
click
on
the image and properties, Event, On Click ... I have the following
VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this correct?
If I click on the proerties for the form, Event, on CUrrent I have
the
following VBA:
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub imgPersonPhoto_Click()
End Sub
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
Private Sub personphoto_BeforeUpdate(Cancel As Integer)
End Sub
Is this right?
When I go to view the form I get an error message: The Expression
On
Current you entered as the event property setting produced the
following
error: Inval;id Outside Procedure.
What does this mean and what do I do?
Thanks so much Jo
:
Hi Jo,
Sorry if it seems that I'm not responding fast enough - but I'm on
the
other
side of the world! This post of yours was at 10:14 PM (after I
closed
down
on Saturday night), with your subsequent post (a follow-up with
essentially
the same content) at 2:42 AM. I'm certainly not giving up on you
;-)
You're on the right track, but missing a couple of important
points.
First, and most important, the entry you have in the textbox is
incorrect,
and that is giving you the #Name? error. The Control Source for
the
textbox
should simply be [personphoto] (the square brackets are not
necessary
if
the
field name does not contain any spaces); and the form's Record
Source
must
be the table containing the personphoto field (or a query based on
that
table).
The code as you posted it will not run, because the actual code is
not
in
the event handler (the Sub personphoto_AfterUpdate() ). The code I
posted
must go between the "stub" which is generated when you click on the
...
button for the Event Procedure; in other words, what you need is:
Private Sub personphoto_AfterUpdate()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
This code will only run when the content of the textbox (and, since
it's
a
bound control, the content of the field in the table for the
current
record)
is changed. As I said, you need it if you want to use the textbox
as
a
means of entering/editing the picture file data.
If you already have the data entered in your table, then to display
it
in
your form when the form opens, or when you move to a different
record,
you
need this same code in the Current event of the form itself. You
need
to
have an Event Procedure for the form's Current event, and it will
look
like:
Private Sub Form_Current()
If Not IsNull(Me.personphoto) Then
Me.imgPersonPhoto.Picture = Me.personphoto
Me.imgPersonPhoto.Visible = True
Else
'hide image control if no picture
Me.imgPersonPhoto.Visible = False
End If
End Sub
If you enter all of this directly into the VBA editor, you will
possibly
(probably) find that it is not attached to the form's current
event.
You
must have [Event Procedure] in the current event of the form's
property
sheet.
If you want to use the same technique in a report, you need to put
the
code
into the Format event of the section of the report where the image
control
is located.
And finally, the line which appears in green is a comment line,
rather
than
executable code. in the VBA editor, anything following a
single-quote
character (except where the single-quote is contained in a
double-quoted
text string) is considered to be a comment. Including comments is
a
useful
way of documenting what your code is (supposed to be) doing. You
can
have a
complete line as a comment (as in the sample I posted), or you can
include
the comment at the end of a line, thus:
Me.imgPersonPhoto.Visible = False 'hide image control if no
picture
HTH, and please post again if you're still having problems (but
remember
that we're out-of-sync with our times),
Rob
Hi Rob. OK.
Have made new table with text field called personphoto.
Have made new form with an image in. It asked me to browse to an
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.