How To Transfer Data From TextBox to a ListBox Using User-Defined Function


Access 2016 VBA Programming : How To Transfer Data From TextBox to a ListBox Using User-Defined Function.

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðŸ“ē Enroll Now: https://bit.ly/2WcbRhX

[Screenshot]


★ YouTube Video ★


★ Related Videos ★
» How to count number of items in a ListBox Control.


» How to MOVE item in the ListBox Control Up and Down.

—Part 1/2.


—Part 2/2.



Thank you for watching
» Don't Forget to Like, Comment, Share and Subscribe to my #YouTube Channel.

Source Code
Link: ~ https://goo.gl/Caqmiq

Option Compare Database
Option Explicit

Private Sub cmdAdd_Click()

Dim c As Control
Set c = Me.ListBox1

With c
     .ColumnCount = 2
     .RowSourceType = "Value List"
     .ColumnWidths = "1.5cm;3cm"
     .BoundColumn = 2
End With

Set c = Nothing

If IsNull(Me.txtItem1) Or IsNull(Me.txtItem2) _
   Or Me.txtItem1 = "" Or Me.txtItem2 = "" Then MsgBox "Please enter something to TextBox.": Me.txtItem1.SetFocus: Exit Sub

Dim str1 As String, str2 As String

str1 = Me.txtItem1.Value
str2 = Me.txtItem2.Value

Me.ListBox1 = AddItemToTheList(ListBox1, str1, str2)

Call CountItemsCommand

Rem cr. Code A Minute

End Sub

Private Sub cmdClear_Click()
     Me.ListBox1.RowSource = ""
     Me.txtItem1.Value = ""
     Me.txtItem2.Value = ""
     Me.TextCount = Null
     Me.TextCount = 0
     Me.txtItem1.SetFocus
End Sub

Function AddItemToTheList(ByVal ctlListBox As ListBox, _
                                                  ByVal itm1 As String, ByVal itm2 As String)
     ctlListBox.AddItem Item:=itm1 & ";" & itm2
End Function

Private Sub CountItemsCommand()

Dim myList As Control
Set myList = Me.ListBox1

Dim iRow As Integer
iRow = 0

With myList
     If .ListCount > 0 Then
          iRow = .ListCount
     Else
          ' Exit Sub
     End If
End With

Me.TextCount = iRow

Set myList = Nothing

End Sub

★ Follow me on ★

Twitter
» https://twitter.com/#!/IBasskung

Facebook (English)
» https://www.facebook.com/CodeAMinute

Facebook (āļŠāļģāļŦāļĢัāļšāļ„āļ™āđ„āļ—āļĒ)
» https://www.facebook.com/IbasskungTutorial

Google+
» https://plus.google.com/u/0/107523775437712370629/posts

YouTube Channel
» http://www.youtube.com/user/TheRockmankung

Dailymotion Channel
» http://www.dailymotion.com/Ibasskung-Courses

Free Source Code can be found here:
» https://goo.gl/UNNzp2

Thank you very much.
āļ‚āļ­āļšāļ„ุāļ“āļ„āļĢัāļš.

#CodeAMinute #AccessVBA #Programming #UserDefinedFunction #IbasskungTutorial

Comments