>I don't want the ID (Primary key) shown in the datagrid, I >guess I can hide the column in the grid by giving it width = 0.
>Is that how it's generally done?
Do not set the Width to 0 if you do not want the user to have the capability of showing it again. Instead, use:
DataGrid1.Column.Visible = False
>Or is the bookmark property used to hold the ID field?
Depends on how you are doing this (passing the data to the sub form).
There are several ways, and I am assumming, or I guess I see that you are opening another recordset object in the sub form.
In the following suggested methods, it is best to use a client side cursor and a disconnected recordset.
You could also just pass the main form's recordset object to the sub form, or even using a cloned recordset object (pass myRS.Clone) if preferred (as long as Bookmarks are supported - this is more effecient than opening another recordset object). The Bookmarks used will be the same for the original and cloned, and an Update affects both the same, unless the Requery method of the original or cloned recordset is called.
I think less overhead, and less chance of mistakes, than the Clone method, would be the often overlook possibility of just passing the Fields collection as a single record:
'Setting the Sub form's "record" property from the Parent Form:
Set MySubForm.myRecord = myRS.Fields
to an object variable in the sub form, as in:
'Sub Form
Option Explicit
Private mMyRecord As ADODB.Fields
Public Property Set myRecord(vRecord As ADODB.Fields)
Set mMyRecord = vRecord
End Property
And then access the record's field as in:
mMyRecord.Item("SomeField").Value
In the sub form you can then use an INSERT Statement or Stored Proceedure action off of the Connection\Command Object to update the db table, and when the sub form is closing, pass a boolean back to the parent form to see if the local copy recordset needs an Update or BatchUpdate.
If using an INSERT Statement or Stored Proceedure to update with, then the parent form's recordset should be disconnected and just the Update method called (No Batch Updating needed then).
You just cannot use AddNew with the Fields collection in this sub form, or move to another record, without having the actual recordset object available.