
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