'VBA Error 80010108 when inserting Rows to Table

I'm asking for help today because I'm just blocking and can't figure out where does my issue comes from.

I'm using Excel UserForms to Insert Data into different Sheets. One of this UserForm (let's call it UserForm1) insert data into 2 differents sheets because of my Database Schema (It's working properly).

UserForm1 Code :

'Enregistrement de la FOURNITURE
Data = Array(Me.txtNom.value)
Call ModuleData.InsertIntoTable("Fournitures", data)

Set ws = Worksheets("Fournitures")
IDProduit = getLastId(ws)

Set ws = Worksheets("Produits")

Data2 = Array(IDProduit, Me.txtNom.value, Me.cboFamilleProduit.value, Me.txtCommentaire.value)

Call ModuleData.InsertRelation(ws, Data2)

'Msg de validation de l'enregistrement
 MsgBox "Le Produit a bien été ajouté à la base de données"
            
'Fermeture du formulaire
Unload Me

Another UserForm is doing the exact same thing and is working too. Let's call it(UserForm2)

UserForm2 code :

data = Array(Me.txtRef.value)
Call ModuleData.InsertIntoTable("Fournitures", data)
'Création de l'enregistrement dans la table
Set ws = Worksheets("Fournitures")
IDMachine = getLastId(ws)
                    
Set ws = Worksheets("Machines")
'Récupération du dernier ID enregistré, et incrémentatio

Data2 = Array(IDMachine, Me.txtMarque.value, Me.txtRef.value, Me.cboType.value, Me.txtPuissance.value, Me.cboUnite.value, Me.cboRobotisation.value, Me.txtAnnee.value, Me.txtCapacite.value, Me.txtCommentaire.value)
                    
Call ModuleData.InsertRelation(ws, Data2)

'Fermeture du formulaire
MsgBox "La machine a bien été ajouté à la base de données"

Unload Me
Function InsertRelation(ws As Worksheet, DataToInsert As Variant)
    Dim count As Integer
    Dim newRow As ListRow
    Dim i As Integer
    count = UBound(DataToInsert) - LBound(DataToInsert) + 1
    
    If count <> ws.ListObjects(1).ListColumns.count Then
        
        MsgBox "L'ajout ne peut pas être effectuer le nombre de données saisie ne correspond pas à la table"
        Exit Function
    ElseIf checkDuplicate(ws, DataToInsert) = True Then
    
         MsgBox "Un doublon a été détecté et n'a pas été saisi, le reste de la saisie à bien été effectuée"
         Exit Function
    Else
       'THERE MY CODE IS CRASHING WHEN UserForm1 Call Insert Relation Procedure
        Set newRow = ws.ListObjects(1).ListRows.Add
        i = 1
        For Each Data In DataToInsert
            newRow.Range(i) = Data
            i = i + 1
        Next Data
    End If
End Function

I'm using a third form that needs, data inserted using UserForm1 or UserForm2. In case of missing data UserForm3 offer the possibility of calling others Forms to insert the missing data. When I call UserForms2 from UserForm3 it works perfectly. But when I'm trying to use UserForm1 when called by UserForm3 Excel crash and restart after printing this error crash

This is kind of mysterious.

Any Help would be higly appreciated.

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source