Putting the code I suggested in the form's Open event procedure should give
you what you are looking for. It doesn't actually insert an empty record
into the table, but shows the form at a 'new record', i.e. un unsaved
record. Saving an empty record to the table is not advisable, and
unnecessary. The user will see the form with all the controls in place, but
empty. This also means you don't need to allow Nulls in all fields, so you
can set the Required property of relevant fields to true, and set their
DefaultValue property where appropriate. Most importantly it means you can
define one or more fields as the primary key.
The question then arises as to whether you want the users to be able to
enter data into the empty new record. If they do it will 'Dirty' the form,
i.e. initiate a new record, which will then be saved if the user closes the
form, moves to another new record or otherwise explicitly saves the record.
If you don't want the users to be able to enter data into the new record,
but only see the empty unsaved record rather than the completely empty form
you can disable all the controls by putting the following code in the form's
Load event procedure:
Dim ctrl As Control
On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = Not Me.NewRecord
ctrl.Locked = Me.NewRecord
Next ctrl
Note that this will disable and lock ALL controls on the form, so if you
have any controls you still want active, e.g. a command button to close the
form, you'd need to exclude them. The best way to do this is to set the Tag
property of any controls you want to remain active to:
KeepMeActive
You can then amend the code:
Dim ctrl As Control
On Error Resume Next
For Each ctrl In Me.Controls
If ctrl.Tag <> "KeepMeActive" Then
ctrl.Enabled = Not Me.NewRecord
ctrl.Locked = Me.NewRecord
End If
Next ctrl
Ken Sheridan
Stafford, England