How to send Excel listbox data into ms access database (1 Viewer)

ajkua

New member
Local time
Today, 05:54
Joined
Nov 1, 2017
Messages
2
Hi All,

I am very new in access and excel i have develop some tool for our knowledge but i am getting confused. My question is below.

I have a list box data i like to send listbox data into database table and when listbox data send to database table listbox data need to delete below is my code please help me

Private Sub CommandButton1_Click()
Dim cn1 As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim dbPath
Dim x As Long, i As Integer




dbPath = Sheets("Export").Range("I3").Value
Set cn1 = New ADODB.Connection

cn1.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath

Set rs1 = New ADODB.Recordset 'assign memory to the recordset

rs1.Open Source:="tblassetentry", ActiveConnection:=cn1, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable

For i = lstViewEWaste.ListCount - 1 To 0 Step -1
If lstViewEWaste.Selected(i) = True Then
rs1.AddNew
rs1("ID") = lstViewEWaste.List(lstViewEWaste.ListIndex)
rs1("UserID") = lstViewEWaste.List(lstViewEWaste.ListIndex)
rs1("AssetCategory") = lstViewEWaste.List(lstViewEWaste.ListIndex)
rs1("Brand") = lstViewEWaste.List(lstViewEWaste.ListIndex)
rs1.Update
End If
Next
MsgBox "Data Insert Sucessfully"
End Sub

and output in all field return 1 like below

ID 1
UserID 1
AssetCategory 1
Brand 1
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:24
Joined
Aug 30, 2003
Messages
36,124
I haven't worked with an Excel listbox, but in Access it has a column property:

ListboxName.Column(C, R)

Where C is the column desired (zero based) and R is the row.
 

Users who are viewing this thread

Top Bottom