Error on Insert Into

  • Thread starter Thread starter Caburky via AccessMonster.com
  • Start date Start date
C

Caburky via AccessMonster.com

I have 3 Tables - that each have their own data entry form. All 3 tables are
related through a one to one relationship.

I have added the following code to the AfterInsert event of the parent form:

Private Sub Form_AfterInsert()
If Me.NewRecord = True Then
CurrentDb.Execute "Insert Into Table2 (ClientID) Values(" & Me.ClientID &
")", dbFailOnError
CurrentDb.Execute "Insert Into Table3 (ClientID) Values(" & Me.ClientID &
")", dbFailOnError
End If
End Sub

After completing the parent form I encounter a compile error when I put my
cursor in the subform – method or member not found. If I stop the debugger
and return to the subform I am able to continue to the subform displaying the
correct ClientID. It seems like a a timing thing, as though my parent form
is not saving to Table1 quickly enough. Do I need to add another step or is
it perhaps on the wrong event?
Thank you!!
 
Caburky said:
I have 3 Tables - that each have their own data entry form. All 3 tables are
related through a one to one relationship.

I have added the following code to the AfterInsert event of the parent form:

Private Sub Form_AfterInsert()
If Me.NewRecord = True Then
CurrentDb.Execute "Insert Into Table2 (ClientID) Values(" & Me.ClientID &
")", dbFailOnError
CurrentDb.Execute "Insert Into Table3 (ClientID) Values(" & Me.ClientID &
")", dbFailOnError
End If
End Sub

After completing the parent form I encounter a compile error when I put my
cursor in the subform – method or member not found. If I stop the debugger
and return to the subform I am able to continue to the subform displaying the
correct ClientID. It seems like a a timing thing, as though my parent form
is not saving to Table1 quickly enough. Do I need to add another step or is
it perhaps on the wrong event?


I think the form's AfterUpdate event might be better.

I also believe that you need to requery the other subforms
after the records are added.

Note that all but the actual record creation would be
automatic if you could use the LinkMaster/Child properties
to syncronize the three subforms.
 
Marshall thank you for your reply.
I'm new to access perhaps you can help me understand. If I have ClientID in
Table1 and ClientID in Table2 and relate them one-to-one, how does Table2 get
the ClientID if ClientID in Table1 is an Autonumber?

Marshall said:
I have 3 Tables - that each have their own data entry form. All 3 tables are
related through a one to one relationship.
[quoted text clipped - 16 lines]
is not saving to Table1 quickly enough. Do I need to add another step or is
it perhaps on the wrong event?

I think the form's AfterUpdate event might be better.

I also believe that you need to requery the other subforms
after the records are added.

Note that all but the actual record creation would be
automatic if you could use the LinkMaster/Child properties
to syncronize the three subforms.
 
Marshall,
I was working too hard to do a simple thing. I removed all of the code and
let the LinkMaster/Child do as it was intended and it worked very easily.
Thank you very much for getting me right to the point.
Marshall thank you for your reply.
I'm new to access perhaps you can help me understand. If I have ClientID in
Table1 and ClientID in Table2 and relate them one-to-one, how does Table2 get
the ClientID if ClientID in Table1 is an Autonumber?
[quoted text clipped - 10 lines]
automatic if you could use the LinkMaster/Child properties
to syncronize the three subforms.
 
Back
Top