Duplicate Inserts (1 Viewer)

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
Hi Everyone

I am attaching the relevant Objects to test my process.

The Form that displays at startup is showing 2 Records.

The 1st record has 1 Participant - Jennifer Corkindale
The 2nd record has 2 Participants - Kirsty Moore & Kirsty Edwards

If you click on the Command Button "Insert Participant Details" for the 1st record it will give the correct Record Count of 2 and inform you that the record has been inserted.

If you then click on the Command Button for the 2nd record it will give the correct Record Count of 2 and inform you that the record has been inserted.

However, when you open "tblGroupCourseParticipants" you will see that it has duplicated each of the inserts and displays as follows:-

Dup.JPG

If anyone can help in trying to solve this problem it would be appreciated.
View attachment Test.zip

Please Note< This has also been cross posted http://www.utteraccess.com/forum/index.php?showtopic=2048226&st=0&p=2677553&#entry2677553
 

static

Registered User.
Local time
Today, 15:40
Joined
Nov 2, 2015
Messages
823
I don't understand why a record count of 2 is correct for the first record if you are only adding one record.

The data is duplicated twice because you have 2 records. If you had 5 records it would be duplicated 5 times.

Remove the loop

You will still get duplicates if you click the buttons multiple times.

Code:
        'With RS
         '   .MoveLast
         '  .MoveFirst
         '   MsgBox .RecordCount
            'Do Until .EOF
           ' rstOtherTable.AddNew
            
                If Len(ParticipantName1 & vbNullString) > 0 Then
                  rstOtherTable.AddNew
                  rstOtherTable![BookingNumber] = lngBookingNumber
                  rstOtherTable!ParticipantName = ParticipantName1
                  rstOtherTable.Update
                End If
                If Len(ParticipantName2 & vbNullString) > 0 Then
                  rstOtherTable.AddNew
                  rstOtherTable![BookingNumber] = lngBookingNumber
                  rstOtherTable!ParticipantName = ParticipantName2
                  rstOtherTable.Update
                End If
                If Len(ParticipantName3 & vbNullString) > 0 Then
                  rstOtherTable.AddNew
                  rstOtherTable![BookingNumber] = lngBookingNumber
                  rstOtherTable!ParticipantName = ParticipantName3
                  rstOtherTable.Update
                End If
                If Len(ParticipantName4 & vbNullString) > 0 Then
                  rstOtherTable.AddNew
                  rstOtherTable![BookingNumber] = lngBookingNumber
                  rstOtherTable!ParticipantName = ParticipantName4
                  rstOtherTable.Update
                End If
                If Len(ParticipantName5 & vbNullString) > 0 Then
                  rstOtherTable.AddNew
                  rstOtherTable![BookingNumber] = lngBookingNumber
                  rstOtherTable!ParticipantName = ParticipantName5
                  rstOtherTable.Update
                End If
            
               '.MoveNext
            'Loop
        'End With
 

isladogs

MVP / VIP
Local time
Today, 15:40
Joined
Jan 14, 2017
Messages
18,213
Mike

Haven't you posted this before recently here or at another forum as I remember seeing it previously.
 

mike60smart

Registered User.
Local time
Today, 15:40
Joined
Aug 6, 2017
Messages
1,904
Hi static & ridders

ridders

I have posted previously on this topic and thought it was resolved but on testing further I found that it was not performing as expected as stated in my question.

I have since had a resolution of this by commenting out the following code lines:-

Do Until .EOF
Loop

It now does as expected :):)

Many thanks for the help
 

Users who are viewing this thread

Top Bottom