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
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: