Bonjour
je n'arrive pas à comprendre pourquoi l'enregistrement du contenu lisbox dans des tables access différentes se fait corectement , par contre il ya un décalage si j'utilise la meme table avec des collones différentes.
se code fonction correctement à l'enregistrement dans deux tables différente;
comment puis-je faire pour enregistrer plusieurs listbox dans une seule table et chaque listbox dans une collonne.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Private Sub Buttonsave_Click()
 
Dim oConn As ADODB.Connection
Dim sConn As String
Dim sSql As String
Dim aListArr() As String
Dim bListArr() As String
Dim i As Integer
Dim j As Integer
Dim K As Integer
 
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mabase.mdb;Jet OLEDB:Database password=mypass" 'connection string
Set oConn = New ADODB.Connection 'istanciate the connection object
oConn.Open sConn 'open the connection
'Read all of the listbox items to an array
For i = 0 To List1.ListCount - 1
List1.ListIndex = i 'move the cursor to the next item in the listbox
ReDim Preserve aListArr(i) 'increase the size of your array to accept _
                            the list box text
aListArr(i) = List1.Text 'set the value of the array
Next i 'loop back to the begining if condition is not met
On Error Resume Next
For i = LBound(aListArr) To UBound(aListArr) 'set the size of the _
                                        loop using the size of the array
sSql = "INSERT INTO MATABLE1 (MACOLONE1) VALUES('" & aListArr(i) & "')"  'Your SQL statment
oConn.Execute sSql 'stick the value of the array in the database
Next i 'loop back to the beginning of this loop if end condition is not met
'Set oConn = Nothing 'clean up
'=========================================================
For j = 0 To List2.ListCount - 1
List2.ListIndex = j 
ReDim Preserve aListArr(j) 
aListArr(j) = List2.Text 
Next j 
For j = LBound(aListArr) To UBound(aListArr) 
sSql = "INSERT INTO MATABLE2 (MACOLONE2) VALUES('" & aListArr(j) & "')" 
oConn.Execute sSql 'stick the value of the array in the database
Next j 
end sub