Oops! I get the following error when I place your code in a command
button
instead of the Afterinsert Event:
CurrentDb.Execute sSQL, dbFailOnError dbfail on error 128:
I'll keep playing, but further insight would be appreciated. Thanks!
--
Gary in Michigan, USA
:
Hi Gary
Is txtTerm bound to a field that is related to some other table? The
five
numbers you mention sound like they are primary key values in another
table.
If so, then I would add a boolean (yes/no) field "AddByDefault" to
that
table and execute an append query in your form's AfterInsert event.
Your code would look something like this:
Private Sub Form_AfterInsert()
Dim sSQL As String
sSQL = "Insert into tblModelInfo select " _
& Me!ModelID & " as ModelID, TermID as Term " _
& "from Terms where AddByDefault<>0;"
CurrentDb.Execute sSQL, dbFailOnError
End Sub
Of course, you would need to tweak the above to suit your own table
and
field names.
If my assumption is wring, and these are just five arbitrary values,
then
you should store then in a table and not hard-code them in your VBA.
That
will make it much easier to change the values in the future if
necessary.
Create a table, "tblDefaultTerms" with one numeric field "Term". Add
in
five records, one for each default value. Now your AfterInsert code
should
look like this:
Private Sub Form_AfterInsert()
Dim sSQL As String
sSQL = "Insert into tblModelInfo select " _
& Me!ModelID & " as ModelID, Term " _
& "from tblDefaultTerms;"
CurrentDb.Execute sSQL, dbFailOnError
End Sub
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
Hi- I have a form, frmModelInfo bound to tblModel, and a subform,
tblModelinfoSubform1, bound to tblModelInfo. For every new record
entered
in
frmModelInfo I would like to get 5 default records displayed in the
subform,
with the default values in certain text boxes on each record. The
particular
text box is txtTerm, and I would like to have 24, 30, 36, 39, and 48
set
up
as defaults. How could I do this? Thanks so much.