"Addnew" code

Anders

New member
Local time
Today, 16:00
Joined
Apr 13, 2001
Messages
5
I have some different controls on a form (textboxes, checkboxes etc). When I press a button, I want to insert whats in the controls in a table. Below code is what I have on that (it seems to work fine):
----------
Private Sub Cmdaddnew_Click()

Set db = CurrentDb
Set rs = db.OpenRecordset("tblvessels")

With rs
.AddNew
.Fields("VesselID") = Me.txtvesselid.Value
.Fields("Vesselname") = Me.Txtvslname.Value
.Fields("Ongoing") = Me.Chkongoing.Value
.Update
End With

End Sub
----------
I have a few questions.
1. If I want to Edit an existing record, in stead of adding it, how does that look in code?

2. Above only adds a record in one table. What do I do, if I want to update two tables, and the the fields "VesselID" and "Vesselname" are in both the tables?

Pls help, since I'm a bit stuck.
 
Why not just bind your table to your form? Then you don't need all the coding behind the scenes.

To do this, just create a new form, and follow the wizard. Or put a table name in your form recordsource, and drag and drop field names from the field list box.

Hope this helps,

Peter De Baets
Peter's Software - MS Access tools http://www.peterssoftware.com
 

Users who are viewing this thread

Back
Top Bottom