Hello in this article I will show you how to insert data from textbox to listbox in Microsoft Access.
this example I designed my form like that
I have 4 Textbox first I named it txtid, txtname,txtage, txtphone and I create two button and named btnsave and remove all so created listbox in my form too.
for listbox property I customize some points look like that :
Now I create Add event with btnAdd by click on INSERT button and click on Property Sheet and select on Tap Event select OnClick Event
Here is my code :
// Code
Option Compare Database
Option Explicit
Private Sub btnInsert_Click()
Dim id As String
Dim name As String
Dim age As Integer
Dim phone As String
id = txtId.Value
name = txtName.Value
age = txtAge.Value
phone = Text14.Value
List5.RowSource = List5.RowSource & ";" & id & ";" & name & ";" & age & ";" & phone & ""
List5.ColumnHeads = True
txtId = ""
txtName = ""
txtAge = ""
Text14 = ""
End Sub
And now we test :
Okay now we start with how to remove item from ListBox follow with my code :
Private Sub btnRemove_Click()
Dim i As Integer
For i = 0 To List5.ListCount
//loop count item in listbox
If List5.Selected(i) Then
//select item of i
If MsgBox("Are you want to remove?", vbYesNo, "Question") = vbYes Then
List5.RemoveItem (i)
End If
End If
Next i
End Sub