insert sql is inserting multiples of the same row?

KjWhal

Registered User.
Local time
Today, 08:46
Joined
Jan 5, 2007
Messages
60
Here is the code

Code:
 Dim insertStatement As String
    
    insertStatement = "INSERT INTO tableDisplay (name, manufacturerID, cableID, transportInterfaceID, powerCableID, backLightInverterID, notes) " & _
                      "VALUES ('" & subFormDisplay!modelNameTextBox & "', " & _
                      subFormDisplay!selectModelManufacturerComboBox & ", " & _
                      subFormDisplay!selectModelCableComboBox & ", " & _
                      subFormDisplay!selectModelTransportInterfaceComboBox & ", " & _
                      subFormDisplay!selectModelPowerCableComboBox & ", " & _
                      subFormDisplay!selectModelBackLightInverterComboBox & ", '" & _
                      subFormDisplay!modelNotesTextBox & "')"

    
    'DoCmd.SetWarnings (False)
    DoCmd.RunSQL (insertStatement)
    DoCmd.SetWarnings (True)
    
    selectDisplayComboBox.Requery

When I run this 2 or 3 identical records will appear, despite the warning saying only 1 row is about to be appended.
 
Kj,

I don't see any way that that SQL statement inserts multiple rows.

When is the code run? Is it possible that it is getting invoked
multiple times?

Wayne
 
Kj,

I don't see any way that that SQL statement inserts multiple rows.

When is the code run? Is it possible that it is getting invoked
multiple times?

Wayne

The code is run during a Click Event

I have stepped through it and it only runs once, but the record appears 2-3 times.
 
I'm guessing that something is not set properly in the relationships, so that when you create a record it is making multiples to compensate for having to create separate records in another table (I had that happen before). With the actual database being posted, it would make it easier to troubleshoot.
 
Anyone who wants to take a crack at it can check the attachment I uploaded.
 

Attachments

Before I go further we need to make some changes to your tables. You are currently using "name" as field names in several tables. This is not good as it is an Access reserved word. So, for the tableDisplay table, you should make the name column something like DisplayName instead of just name. Make your fields meaningful so that outside of the table you know what they are. Also, if you do that type of a name, you won't probably use an Access reserved word.

Without asking a LOT of questions, I'm not sure how we'll get through the relationship issues. Hopefully Wayne can help on this too. Something just doesn't seem right about the way the relationships are set up.

Also, can you remind me as to which items to select and click to try to recreate your initial problem?
 

Users who are viewing this thread

Back
Top Bottom