Adding multiple records to subform

Novice1

Registered User.
Local time
Today, 15:42
Joined
Mar 9, 2004
Messages
385
I want to add several records to the subform. This works until line 4 (error 2105; can't go to specified record. Can't I keep adding records?

Me.frmMissingItems_Subform.SetFocus

DoCmd.GoToRecord , , acNewRec
Forms!frmPCSTracker!frmMissingItems_Subform!MissingID = "1"

DoCmd.GoToRecord , , acNewRec
Forms!frmPCSTracker!frmMissingItems_Subform!MissingID = "2"

DoCmd.GoToRecord , , acNewRec
Forms!frmPCSTracker!frmMissingItems_Subform!MissingID = "3"
 
Data is stored in tables. If you want to add data, add it directly to the table.
Code:
const SQL_INSERT as string = _
   "INSERT INTO tMyTable ( Field1 ) " & _
   "VALUES ( p0 )"
 
with currentdb.createquerydef("", SQL_INSERT)
   for i = 1 to 4
      .parameters("p0") = i
      .execute
   next
end with
See what's going on there? Then maybe you have to requery the form to show your work.
 
The table has a many to many relationship with the primary table. Will the data have the relationship if added directly to the table?
 
As the programmer, you know what those relationships are, and that data is available on the form.
Code:
const SQL_INSERT as string = _
   "INSERT INTO tMyTable ( [COLOR="Blue"]ParentID, [/COLOR]Field1 ) " & _
   "VALUES ([COLOR="Blue"] p0, [/COLOR]p1 )"
 
with currentdb.createquerydef("", SQL_INSERT)
[COLOR="Blue"]   .parameters("p0") = Me.ParentID[/COLOR]
   for i = 1 to 4
      .parameters("p1") = i
      .execute
   next
end with
In blue we include data to relate the new record to the parent.
 

Users who are viewing this thread

Back
Top Bottom