How to add an attachment type field to an existing form

B

Billiam

I need to remove a picture field from my Access 2007 tblInstructors as I am
using Allen Browne's Audit table which of course does not support
multi-valued fields. So, I have set up a new table called
tblInstructorPicture, in a 1 to many relationship with TblInstructor (one
instructor can have 0, 1 or more pictures). I would like to add the picture
field from this new table to an existing form based on tblInstructor. Can I
still use the Attachment datatype in the new tbl, I ask this as I tried to
make a union query on which to base a new form and it would not allow it
since the attachment datatype is a multivalued field....

Short version is, I have 500 Instructor pictures to try and get back on the
form we were using for data entry which is based on tblInstructors. Any help
appreciated!
Thanks,
Billiam
 
A

Allen Browne

1. Create a related table, with a text field that holds the path to the
attachment (assuming 255 char is enough for the full path.)

2. Put a subform on your instructor form, and show the subform in Continuous
view.

3. In the subform, use an Image control, and set its Control Source propety
to the text field that contains the path. The subform will show the images
(one per row.)

This avoids all the problems of the MVF attachments, so you can audid
tblInstructor. You can audit the subform's table too if you need to do that.

Alternatively, if you don't need to audit the change of attachments and do
want to embed them (not merely link to them), put the attachment field into
the related table (shown in the subform), so you can still audit the main
table.

The other alternative is to create your own audit code, so it does handle
attachments and MVFs. I haven't tried, but I don't imagine this is a trivial
task, especially as Access doesn't handle the timing of these updates well,
and doesn't report the OldValue properly.

(BTW, the ability to use the ControlSource of the Image control is new in
Access 2007.)
 
B

Billiam

Hi Allen,

Thank you very much for helping me out again, I'm honoured!!!

Which of the options you suggested is the best as far as performance is
concerned?

As I am new to Access and database design generally, I am slightly confused
about form design and I am wondering if you could clear a couple of things up
for me...

1. I thought with a properly normalized design and relationships set up
that you would use a query to "reassemble" the tables to build your form
from...is this correct? The reason I ask, is I thought that I could simply
seperate the existing attachment field (called BMP) from the original table
that the form was based on, and reattach it through a query so as to not
interfere with the requirements of not having a multi valued Field in the
Audit procedure you created...I believe when i tried this I received an error
such as "You cannot base a query on a table that the form is already based
on...or something like that?

My goal is to not have to change the original Instructor Input Form which
the enduser, my boss, is used to...simply there is a bound image frame in the
original Instructor Input form...in other words, I do not want to add a
subform because I think it will not look right since I do not know if it can
be made to simply look like a picture frame...which is how it looked before
adding the audit procedure.

Finally, when you resolve a many to many relationship with a
junction/intermediate table, how do you turn all the foreign keys into
something usable?
For example, I have a tblInstructor and a tblAddress both in a one to many
relationship with tblInstructorAddress (the junction/intermediate table).
Also, a seperate table called tblAddressType is in a one to many relationship
as a foreign key in the junction table. When I design my form, do I use a
query to link up all the info again (Instructor name, Instructor Address
type, Address), or merely the address info as a subform of the Instructor for
which contains Instructor details such as name? I seem to be unable to get
all of the address info connected, specifically the address type with the
address...I know this is off topic, and so if you would rather i post as a
new question in the form Forum, I would be happy to.

Again, many thanks for your help, Allen!!!
 
A

Allen Browne

Responses in-line.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Billiam said:
Which of the options you suggested is the best as far as performance
is concerned?

The first alternative would be my suggestion. (More a matter of what's the
best design for what you need than performance.)
...wondering if you could clear a couple of things up for me...

1. I thought with a properly normalized design and relationships set up
that you would use a query to "reassemble" the tables to build your form
from...is this correct? The reason I ask, is I thought that I could simply
seperate the existing attachment field (called BMP) from the original
table
that the form was based on, and reattach it through a query so as to not
interfere with the requirements of not having a multi valued Field in the
Audit procedure you created...I believe when i tried this I received an
error
such as "You cannot base a query on a table that the form is already based
on...or something like that?

You can create a query from multiple tables, and then base a form on that,
but the results may not be desirable. For example, if one person has
multiple pictures associated with them, they will appear multiple times in
the query, and therefore multiple times in the form. It would be better to
use a form, with a subform for the pictures. Then the person appears once
only in the main form, and the multiple pictures show in the subform.

You may also find that a multi-table query is read-only, so you can't edit
anything in the form. Here's a check list if you hit that:
Why is my query read-only?
at:
http://allenbrowne.com/ser-61.html
But again, basing the main form on a table averts that issue also.
My goal is to not have to change the original Instructor Input Form which
the enduser, my boss, is used to...simply there is a bound image frame in
the
original Instructor Input form...in other words, I do not want to add a
subform because I think it will not look right since I do not know if it
can
be made to simply look like a picture frame...which is how it looked
before
adding the audit procedure.

You can decide which is best for you, given the limitations of each
approach.
Finally, when you resolve a many to many relationship with a
junction/intermediate table, how do you turn all the foreign keys into
something usable?
For example, I have a tblInstructor and a tblAddress both in a one to many
relationship with tblInstructorAddress (the junction/intermediate table).
Also, a seperate table called tblAddressType is in a one to many
relationship
as a foreign key in the junction table. When I design my form, do I use a
query to link up all the info again (Instructor name, Instructor Address
type, Address), or merely the address info as a subform of the Instructor
for
which contains Instructor details such as name? I seem to be unable to get
all of the address info connected, specifically the address type with the
address...I know this is off topic, and so if you would rather i post as a
new question in the form Forum, I would be happy to.

For a many-to-many relation, it's best not to try to do all of this in one
form. You will need a form for instructors (with a subform for selecting the
relevant addresses for them), and another form for entering the addresses
themselves.

That is a valid design, but it may be more complex than you need. Are there
many instructors who share the same address? There might be (e.g. if the
instructors live in army bases, or work out of the same buildings), but
often you might get by without the junction table (i.e. one instructor has
many addresses.)

If you do need to use a many-to-many, here's a screenshot of what it might
look like:
http://allenbrowne.com/unlinked/JunctionAddress.jpg
That's just the top of a form, where you select a client for a job, and then
select one of the client's addresses to deliver the job to (on the right.)
Code in Form_Current and ClientID_AfterUpdate limits the addresses to those
for this client. The button to the right of the address combo pops up
another form for entering a new address and associating it with the client
if you need to do that.

Again, you may not even need the junction table here.

HTH.
 
B

Billiam

Hi Allen,

It looks like I have some more decisions ahead...I love how you have laid
out your form...now I wonder if I can convince my EXTREMLEY
computer-illiterate boss to make the switch!!! (do you have any code to help
that situation, LOL !)

Seriously, it really is great that you take the time to help out like this,
Allen, I really admire you for that, and offer my very sincere thanks! Have a
great week!
Cheers,
Billiam
 

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