DataBase - Add Records From Subform to Table

Asked By NFL
08-Feb-10 09:43 AM
I have a form that links 1 source object to a subform.   The subform list may
be different based on which object is selected on the main form. How can I
write a code to select a textbox field from the subform and add them to a
table?

Thank you for your help!
ComputerID
(1)
PrinterID
(1)
Database
(1)
RoomID
(1)
DbOpenDynaset
(1)
AnotherValue
(1)
SomeValue
(1)
Rooms
(1)
  BruceM via AccessMonster.com replied to NFL
08-Feb-10 03:06 PM
I do not know for sure what you mean by linking a source object to a subform.
I am sure I do not know what you mean by selecting an object on the main form.
A subform control has a source object (the form that serves as a subform), so
perhaps you are saying you want the subform data to correspond to the main
form record.  This is ordinarily accomplished by creating a relationship
between the source tables for the main form and the subform, then selecting
the linking fields as the Link Child and Link Master properties of the
subform control.

If you describe your database's structure and general purpose it may be
possible to offer a more specific suggestion.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201002/1
  NFL replied to BruceM via AccessMonster.com
08-Feb-10 12:01 PM
You're right, I got my terms backward.  Sorry about that.  The subform does
have a source object and it is linked to the main form.  Here is the table set
up.  I will try to make this simple.  Table1 is FORM1,  Table2 is the
(SUBFORM).  I want to be able to create a button to select the items from the
subform and insert it to Table3.

Table1         Table2                           Table3
Room(One)   Room (Many)                  Printer (Many)
Computer                       Room (Many)
Computer
  BruceM via AccessMonster.com replied to NFL
08-Feb-10 06:05 PM
The short answer is that you use the linking properties of the subform
control to add records to the subform's record source table, rather than
using a command button to write to that table via code.  You can do it that
way: open a recordset and write records to it, but that approach is probably
needlessly complicated.

OK, so one room may have many computers and printers, and one printer may be
used by many computers, and one computer may have many printers.  In one
sense a computer or printer is an attirubute of a room.  In another sense the
room is an attribute of the computer or printer.  But is a printer an
attribute of a computer, a room, or both?  How you set up your forms and
subforms depends on what exactly you need to do.  Do you want to look at a
computer's records and see the available or installed printers?  Do you want
to look at a room records and see the printers and computers in it?  Do you
want to look at a printer record and see the computers using that printer,
the room in which the printer is located, or both.

You need a table for each entity:  Rooms, Computers, Printers, Room/computer,
Room/printer, computer/printer.  Beyond that the details depend on the
specifics of your situation.  There really is no generic answer to the
question of how to use a command button to insert records into a table.  In
general it could look something like this:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("Table3", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!ComputerID = Me.ComputerID
rs!PrinterID = SomeValue
rs!RoomID = AnotherValue
If Err Then
MsgBox "Error #" & Err.Number & " (" & Err.Description & ")"
rs.Close
Exit Sub
End If
rs.Update
rs.Close

However, that is unlikely to be the best way to go about it.  You may not
need code at all.






--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201002/1
  NFL replied to BruceM via AccessMonster.com
09-Feb-10 04:32 PM
Thank you for your response.  The form and subform works very well together.
I just do not know how to pass the values from the subform to a different
table.  It might not look right, but there are other inputs the user would
add to that table.
  BruceM via AccessMonster.com replied to NFL
10-Feb-10 12:22 PM
You can open a recordset along the lines of the code I posted.  Where I
showed ComputerID, SomeValue, and AnotherValue you would use the values you
actually want inserted.


--
Message posted via http://www.accessmonster.com
Create New Account
help
Today's Date DataBase Hi all, Ive read the threads about the command to "add Today's Date / Prefill left is work with certain relationships? Id appreciate any help. THANK YOU Access Forms Discussions ComputerID (1) CompuerID (1) Database (1) PermID (1) FaxID (1) DefaultValue (1) PrinterID (1) DblClick (1) Brett, One thing I noticed right off the bat is that if anything into your 'ID' field' further explanation is needed. Remember, we can't see your database so we have no idea what your 'ID' field is or why you want to me that means there is no relationship between the tables, is that true? You say ComputerID is a PK linked to PermID which is a FK BUT PermID stores all of the Inventory values, I'm confused, what is the table that houses ComputerID do? If PermID is in effect the effect the Inventory then shouldn't that be it to get the values filled in on your form? 5. And what purpose does ComputerID have if it's already in the table that houses PermID to your form? Perhaps
Run report in one database from another database DataBase Is there a way to run a report that was built in one database from another database? I have created a fairly complex report in one database that the users of another database need to view, however, there is other functionality in the database with the report that these users should not have access to. I don't want
Link to Database - Password DataBase HI, I have two database in two different folder. One (Database A) of the folder contains all the tables only. Other one is where I use the database (Database B) everyday and the database is linking the other database that has all the tables only. I set the Database B linking to Database A
importing data from one access database to another access database DataBase How do I import selected data and selected records from one access database to another access database. The field names are not currently always the same. I want to add people from one database into another database. Only some of the fields from the first database will be used in the second database. Access Tables DB Design Discussions Database (1) Access