valeurs dans base de donnée ACCESS

cavrom

XLDnaute Nouveau
Bonjour à tous,
Je souhaite envoyer les valeurs d'un tableau sous Excel dans une base de données ACCESS :
j'ai créé une table dans ACCESS nommée T_reverberation, et composé de trois colonne : project, reverberation, frequency et exist.
Le tableau sous Excel me permet d'entre une valeur de reverberation en fonction de sa fréquence. Je souhaite ensuite que ces deux valeurs ( reverberation et frequency) se trouve dans ma base ACCESS, avec le nom du projet correspondant.

Mon code à ce jour est :

Code:
Private Sub Send_reverberation_Click()
'When the user want to send data in access

'Statement of some variables
Dim name_project As String, reverberation As String
'record the name of the project present in the cell B51 in the variable name_project
name_project = Sheets("add").Range("B51").Value

'Opening the database connection with ACCESS
Dim Cnx As ADODB.Connection
Set Cnx = New ADODB.Connection
Cnx.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & ThisWorkbook.Path & "\Database.mdb"

'This sub has to work for all the equipments. So, we have to make a "select case" to know
'for what equipment the values are.
'With the multipage_change in "Userform", we have the equipment in the sheet add in the cell B50

On Error Resume Next


        On Error Resume Next   'This line may already is in the database so it allows to do nothing if there is an error.
            Cnx.Execute ("INSERT INTO T_reverberation (project) VALUES ('" & name_project & "' ) ")

        For i = 1 To 24
            reverberation = "reverberation" & i
            'Access request to upddate the table with the data
            Cnx.Execute ("Update T_reverberation SET " & reverberation & " = '" & Sheets("add").Range("D12").Offset(i, 0).Value & name_project & "' ")
        Next i
        'There is a column in the access table with the word "exist" if there is values for reverberation
        'So we put the word 'exist' in this column
        Cnx.Execute ("Update T_reverberation SET reverberation_exist='exist',dB_reverberation='" & Sheets("add").Range("D37").Value & name_project & "' ")





Sheets("Update").Range("A6").Value = name_project

Cnx.Close
Sheets("add").send_reverberation.Visible = False
Sheets("add").cancel_reverberation.Visible = False
Range("A:A").EntireColumn.Hidden = False
If Sheets("add").Range("C130").Value = "Update" Then
    Sheets("add").Range("B1:E60").ClearContents
    Sheets("add").Range("B1:E60").ClearFormats
    Update_project.Show
Else
    Sheets("add").Range("B1:E60").ClearContents
    Sheets("add").Range("B1:E60").ClearFormats
    UserFormIntMeasure.Show
End If
End Sub

Lorsque je clique sur le bouton "send_reverberation" , les données ne sont pas envoyées dans ACCESS. Savez vous pourquoi? Et si oui, quelle est la démarche à suivre?
Je vous joins un aperçu de mon tableau Excel et ma table ACCESS.
Merci et bonne journée à vous
 

Pièces jointes

  • table reverberation.JPG
    table reverberation.JPG
    21.2 KB · Affichages: 123
  • values.jpg
    values.jpg
    74.9 KB · Affichages: 111
  • values.jpg
    values.jpg
    74.9 KB · Affichages: 114
  • values.jpg
    values.jpg
    74.9 KB · Affichages: 116

Discussions similaires

Statistiques des forums

Discussions
311 720
Messages
2 081 898
Membres
101 834
dernier inscrit
Jeremy06510