A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Code runs twice



 
 
Thread Tools Display Modes
  #1  
Old April 14th, 2009, 07:27 PM posted to microsoft.public.access.forms
dbl[_2_]
external usenet poster
 
Posts: 8
Default Code runs twice

Hi I have a form which when a new record is added adds the field CustomerID
Ref Number to 2 linked tables. Into fields CustomerID2 and CustomerID3

All worked well with no problems with the code below with 1 linked table.

Private Sub Form_AfterInsert()
CurrentProject.Connection.Execute "INSERT INTO tblTheftForm (CustomerID2)
VALUES (" & Me.Field143 & ")"
End Sub

But with 2 tables and the following code it runs into an error stating that
I have duplicate data and the first line of code is highlighted, this only
happens about 50% of the time.
the rest of the time it works fine.

Private Sub Form_AfterInsert()
CurrentProject.Connection.Execute "INSERT INTO tblTheftForm (CustomerID2)
VALUES (" & Me.Field143 & ")"
CurrentProject.Connection.Execute "INSERT INTO tblTelephoneChecklist2
(CustomerID3) VALUES (" & Me.Field143 & ")"
End Sub

I also have the following fields in the query that supports the form and all
the 3 tables are in this query.
CustomerID
CustomerID: CustomerID2
CustomerID: CustomerID3

Has anyone any ideas as to what I am doing wrong.

Thanks Bob



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.