[RESOLVED] Add New Item to ListBox
using Access only, no VB or other front ends used in this app.
i would like to know how to add a new item to a listbox with two columns at the moment my code looks like this:
Code:
If txtDate = "" Then
MsgBox "You must enter a Date for the Operation First, and Click Add.", vbOKOnly, "Error - Missing Date"
Exit Sub
Else
If txtTime = "" Then
MsgBox "You must enter a Time for the Operation First, and Click Add.", vbOKOnly, "Error - Missing Time"
Exit Sub
Else
lstOperationSummary.AddItem ("Date: " & txtDate)
lstOperationSummary.AddItem ("Time: " & txtTime)
End If
End If
however this only writes the "("Date: " & txtDate)" to one column, i wish to have them split so "Date:" goes in the first and txtDate goes in the second.
thanks
Re: Add New Item to ListBox
Quote:
Originally Posted by aztrix
using Access only, no VB or other front ends used in this app.
i would like to know how to add a new item to a listbox with two columns at the moment my code looks like this:
Code:
If txtDate = "" Then
MsgBox "You must enter a Date for the Operation First, and Click Add.", vbOKOnly, "Error - Missing Date"
Exit Sub
Else
If txtTime = "" Then
MsgBox "You must enter a Time for the Operation First, and Click Add.", vbOKOnly, "Error - Missing Time"
Exit Sub
Else
lstOperationSummary.AddItem ("Date: " & txtDate)
lstOperationSummary.AddItem ("Time: " & txtTime)
End If
End If
however this only writes the "("Date: " & txtDate)" to one column, i wish to have them split so "Date:" goes in the first and txtDate goes in the second.
thanks
For multiple-column lists, use semicolons to delimit the strings for each column (for example, "1010;red;large" for a three-column list). If the Item argument contains fewer strings than columns in the control, items will be added starting with the left-most column. If the Item argument contains more strings than columns in the control, the extra strings are ignored.
for example in the above code
Code:
lstOperationSummary.AddItem "Date: ;" & txtDate.Value
Same goes for the second line
Re: Add New Item to ListBox
sweet thanks very much!
now to add to this question, say i have a table that i want to save the listbox data in, how would i then send the contents of the listbox to the table?
my code so far looks like this:
Code:
Dim lngCounter As Long
lngCounter = 0
For lngCounter = 0 To lstOperationSummary.ListCount - 1
Me.Recordset.AddNew
Me.Recordset.Fields("Detail") = lstOperationSummary.ItemData(lngCounter)
Me.Recordset.Update
If lstOperationSummary.Selected(lngCounter) Then
End If
Next lngCounter
MsgBox "Operation Details Saved", vbOKOnly, "Saved"
however, this writes blank fields to my database table :(
Re: Add New Item to ListBox
ok thanks to you koosid, i now have data being written to my table, it was writting the second column of the listbox, and without your code, i had nothing in the second column only the first, hence creating blank records in my table.
so............how do i get it to write the first column and second column?
Re: [RESOLVED] Add New Item to ListBox
Never mind worked it out myself
here it is:
Code:
Dim lngCounter As Long
lngCounter = 0
For lngCounter = 0 To lstOperationSummary.ListCount - 1
Me.Recordset.AddNew
Me.lstOperationSummary.BoundColumn = 1
Me.Recordset.Fields("Code") = lstOperationSummary.ItemData(lngCounter)
Me.lstOperationSummary.BoundColumn = 2
Me.Recordset.Fields("Detail") = lstOperationSummary.ItemData(lngCounter)
Me.Recordset.Update
If lstOperationSummary.Selected(lngCounter) Then
End If
Next lngCounter
MsgBox "Operation Details Saved", vbOKOnly, "Saved"