By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,444 Members | 3,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,444 IT Pros & Developers. It's quick & easy.

One form -> multiple tables

P: n/a
Is it possible to have a data entry form where the information is
stored in several different tables (5 or 6)? I have an inventory
database where Table1 stores all of the data common to all entries,
Table2 stores only the extra info relevant to items that are TYPEA,
Table3 stores only the extra info relevant to items that are TYPEB, and
so on. All relationships are setup (one-to-one) between the main table
(Table1) and all the other tables with the required fields. I can get
it to work with Table1 and one other table, but as soon as I add a
third table it won't let me enter data. Is it a problem in the join
statement? This is the record source SELECT statement that doesn't
work:

SELECT tblInventory.id AS tblInventory_id, tblInventory.AssetTag AS
tblInventory_AssetTag, tblInventory.Make, tblInventory.Model,
tblInventory.serial AS tblInventory_serial, tblPrinters.serial AS
tblPrinters_serial, tblPrinters.inkblacknumber,
tblPrinters.inkcolornumber, tblPrinters.tonerblacknumber,
tblSoftware.id AS tblSoftware_id, tblSoftware.AssetTag AS
tblSoftware_AssetTag, tblSoftware.SoftwareA, tblSoftware.SoftwareB,
tblSoftware.SoftwareC, tblSoftware.SoftwareD
FROM tblSoftware RIGHT JOIN (tblPrinters RIGHT JOIN tblInventory ON
tblPrinters.serial = tblInventory.serial) ON tblSoftware.AssetTag =
tblInventory.AssetTag;

I will entertain most suggestions, but using subforms is not an option.
Hopefully someone can point me in the right direction.

Sep 8 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Why not show the extra information on a 2 sub forms?

"fonzie" <do*******@yahoo.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Is it possible to have a data entry form where the information is
stored in several different tables (5 or 6)? I have an inventory
database where Table1 stores all of the data common to all entries,
Table2 stores only the extra info relevant to items that are TYPEA,
Table3 stores only the extra info relevant to items that are TYPEB, and
so on. All relationships are setup (one-to-one) between the main table
(Table1) and all the other tables with the required fields. I can get
it to work with Table1 and one other table, but as soon as I add a
third table it won't let me enter data. Is it a problem in the join
statement? This is the record source SELECT statement that doesn't
work:

SELECT tblInventory.id AS tblInventory_id, tblInventory.AssetTag AS
tblInventory_AssetTag, tblInventory.Make, tblInventory.Model,
tblInventory.serial AS tblInventory_serial, tblPrinters.serial AS
tblPrinters_serial, tblPrinters.inkblacknumber,
tblPrinters.inkcolornumber, tblPrinters.tonerblacknumber,
tblSoftware.id AS tblSoftware_id, tblSoftware.AssetTag AS
tblSoftware_AssetTag, tblSoftware.SoftwareA, tblSoftware.SoftwareB,
tblSoftware.SoftwareC, tblSoftware.SoftwareD
FROM tblSoftware RIGHT JOIN (tblPrinters RIGHT JOIN tblInventory ON
tblPrinters.serial = tblInventory.serial) ON tblSoftware.AssetTag =
tblInventory.AssetTag;

I will entertain most suggestions, but using subforms is not an option.
Hopefully someone can point me in the right direction.

Sep 8 '06 #2

P: n/a
Using subforms isn't an option, I need it to be on one form.

I will entertain most suggestions, but using subforms is not an option.
Hopefully someone can point me in the right direction.
Sep 8 '06 #3

P: n/a
fonzie wrote:
Is it possible to have a data entry form where the information is
stored in several different tables (5 or 6)?
What about an unbound form (you can have bound listboxes and combos)?
On the OK button run insert statements to plop the screen data into the
appropriate tables.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Sep 8 '06 #4

P: n/a
I am very close with the setup I have now, the problem is when I add
the third table to the select statement I can only view the results in
the form, I can't add or edit of the information. Is this by design?
Does my SELECT statement need to be changed somehow?

Sep 8 '06 #5

P: n/a

fonzie wrote:
I am very close with the setup I have now, the problem is when I add
the third table to the select statement I can only view the results in
the form, I can't add or edit of the information. Is this by design?
Does my SELECT statement need to be changed somehow?
I could be completely outta my mind, but I don't think Access is
designed to do what you are attempting to do. I guess you could base a
form on 3 tables, but I try to stay away from that kind of thing. As
you've found, it's not hard once you have a form with more than one or
two tables as the recordsource, you're going to have problems with the
recordset being updateable. It's the nature of the relational beast, I
think. If I were you, I'd rethink my form design because you may be
asking something that's not impossible, but certainly not easy.

Sep 8 '06 #6

P: n/a
fonzie wrote:
I am very close with the setup I have now, the problem is when I add
the third table to the select statement I can only view the results in
the form, I can't add or edit of the information. Is this by design?
Does my SELECT statement need to be changed somehow?
Based on your other response to Ron, ie restricted to one form, no
subforms, here's what I would do.

I'll assume the fields identified in your join statement are prmary
keys. This is critical.

1) Design your select statement so it displays the records you want it
to. You've pretty much done that. Don't worry that the query doesn't
allow you to edit/add records.

2) Create a continuous form with a footer that displays the fields you
want. You've a fair number of fields that might lend themselves to
having a subform datasheet, but since that's out of the question, you
want to make this a continuous form so that you have a "bare footer"
showing. Maybe two or more rows in the detail section might be
necessary, perhaps with Asset tag in bold or a different colour or
something. Use text boxes to display the information for each record in
the form detail section.

3) Make sure the name property of each text box is NOT, repeat NOT the
same as the controlsource field from the query. I usually name my text
boxes txtFieldName.

4) Set the add, and delete properties on your form's property data tab
to NO. What we are going to do is set up fields in your footer and five
buttons for adding, editing and deleting records.

5) In the tag property of each text box you've just created in the
detail section, write "Display". Make sure all these text boxes are
enabled. You should also lock them - you don't want users to try and
change data in the detail section - that's what the footer secction will
be for.

6) In the footer, duplicate the controls in the detail section BUT MAKE
SURE THERE ARE *NO* CONTROLSOURCES in each text box. In other words,
you turn on your form and there's blank spaces in the controls on the
footer. Name each control as per 3, above, perhaps with Add as a
suffix, such as txtFieldNameAdd.

7) If you want to restrict users to specific data instead of the free
form a text box can potentially allow:

-a) use a combo box with a row source from one a query but with no
controlsource;
-b) use the afterupdate event to restrict what is allowed; and/or
-c) Add constraints in your table field properties with appropriate
messages.

8) For every text/combo control in the footer, mark the Tag property
"DataEntry" and disable them all.

9) Create 5 buttons in the footer. Three are labeled add, edit and
delete. Enable these buttons. Two are labeled OK and cancel and are
disabled. You can use images that clearly indicate the function of each
button.

10) Add a text box that is invisible in the footer and call it txtAddEdit.

11) What you want to be able to do is click one of the three buttons and
have the detail section freeze. Use a sub in the form something like
(All of the following is air code - no error handling will be offered here):

Sub sEnableControls(booEnable as Boolean)

'booEnable is passed as True to enable when adding/editing record
'and false to disable when cancelling or
'accepting addition/edit of a record

dim Ctl as Access.Control

'Enable dataentry controls

for each ctl in me.controls
if ctl.controltype = acTextBox or ctl.controltype = accombobox then
if ctl.tag = "dataEntry" then crl.enabled = booenable
end if
next

'Switch focus to one of the fields in the footer
'so that the following does not throw an error like
'"You can't disable the control that has the focus"

if booenable = True then
me.txtIdAdd.Setfocus
else
me.txtId.Setfocus
end if

'Do the button thing
me.btnAdd.Enabled = not booenable
me.btnEdit.Enabled = not booenable
me.btnDelete.Enabled = not booenable

me.btnOK.Enabled = not booenable
me.btnCancel.Enabled = not booenable

End Sub

When the Edit button is clicked, it loads the current values into the
controls of the footer:

Sub btnEdit_Click

'Set txtAddEdit to "Edit" so app knows what to do
'When OK is pushed.

me.txtAddEdit.Value = "Edit"

'Enable stuff

sEnableControls True

'Populate footer fields

me.txtIdAdd.Value = Me.txtId.Value
me.txtAssetTagAdd.Value = Me.txtAssetTag.Value
'etc, etc - for the add button, set these all to null,
'ie, empty

End Sub

Now, when you have done your additions, etc, set up the ok button as
follows:

Sub btnOK_CLick

dim strS as string
dim db as dao.database
dim qd as dao.querydef

If me.txtAddEdit = "Add" then
'This will mean create and execute three insert statements

'Set Up the db and querydef

set db = Access.Currentdb
'Set up a temporary querydef
set qd = db.Createquerydef("")

'Let's do tblInventory, first

strS = "INsert into tblInventory (" & vbcrlf
strs = strs & "id, AssetTag, " & vbcrlf
strs = strs & "Make, Model, serial)" & vbcrlf
strs = strs & "Select " & vbcrlf
strs = strs & me.txtIdAdd & ", """ & me.txtAssetTagAdd & """, """ &
me.txtMakeAdd & vbcrlf
strs = strs & me.txtModelAdd & ", """ & txtsERIALAdd & """"

with qd
.SQL = strs
.returnsrecords = false
.execute dbfailonerror
end with

'Repeat the above 11 lines for the other tables.

Else
'This will be fr three update statements - you can figure that out.
end if

'IF you get this far, you've been successful, hurrah!
'Enable stuff

sEnableControls False

Exit_Proc

qd.close
set qd = nothing
db.close
set db = nothing

End sub

You can fill in the blanks. I rushed this together before going home
from work. Check things carefully, it's all air code.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Sep 8 '06 #7

P: n/a
Tim Marshall wrote:
I'll assume the fields identified in your join statement are prmary
keys. This is critical.
Actually it's not. See ya, have a good weekend!
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Sep 8 '06 #8

P: n/a
"fonzie" <do*******@yahoo.comwrote in
news:11**********************@e3g2000cwe.googlegro ups.com:
Using subforms isn't an option, I need it to be on one form.
>
I will entertain most suggestions, but using subforms is
not an option.
Hopefully someone can point me in the right direction.
In this case, you have only the options of 1) using a subform, 2)
not showing the data.

Which is the predominant option?

I'd take the subforms over saying I can't do it any day.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 9 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.