I have a listbox with values in it (One column, 6 rows).
If I want a simple one liner to add text into the 4th row, how is it done?
Me.Listbox1.ItemData(4) = "Text to enter"
This does not work.
How do I do it?
I have a listbox with values in it (One column, 6 rows).
If I want a simple one liner to add text into the 4th row, how is it done?
Me.Listbox1.ItemData(4) = "Text to enter"
This does not work.
How do I do it?
add the value to the table. Listbox/Combo boxs are based on query/table.
if your combo/List is based on VALUE LIST, (listbox.RowSourceType) then
lstbox.Rowsource = "red;blue;Text To Enter"
Thank you for the quick reply.. I have no errors now but listbox2 will not populate with anything. Is there a trick to getting the list to update? (Listbox1 does populate and Rowsource does count up and the "NOS" values does execute in the if statement properly to make Listbox2.Rowsource = ".." etc properly.) Listbox2 just does not update at all. It remains blank.
Dim str As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim LOSN As Integer
Dim NOS As Integer
Dim SellableP As Boolean
Dim Rowsource As Integer
On Error GoTo ErrorHandler
Listbox1.Enabled = True
Listbox2.Enabled = True
Set db = CurrentDb
'UnLock controls
Listbox1.Enabled = True
Listbox2.Enabled = True
txtIIRNumber.Enabled = True
'Update Listbox1
Forms!Build1F!Listbox1.Requery
'Go through part numbers in listed BOM and check for SNs - if Main PN = Shipable, put XXXX in IIR #
For Rowsource = 0 To Listbox1.ListCount - 1
With Listbox1
str = ("SELECT * FROM PartsT WHERE EngineeringPN = " & "'" & Me.Listbox1.ItemData(Rowsource) & "'")
End With
Set rs = db.OpenRecordset(str)
If rs.RecordCount = 1 Then
With rs
LOSN = Nz(!LOSN, 0)
NOS = Nz(!NOS, 0)
SellableP = !SellablePart
End With
With Listbox2
If NOS > 0 And SellableP = True Then Listbox2.Rowsource = "XXXXX" 'Shippable parts get xxx in List2
If LOSN = 0 And NOS = 0 Then Listbox2.Rowsource = "...."
If LOSN > 0 And NOS = 1 Then Listbox2.Rowsource = "."
If LOSN > 0 And NOS = 2 Then Listbox2.Rowsource = ".."
If LOSN > 0 And NOS = 3 Then Listbox2.Rowsource = "..."
End With
End If
Next Rowsource
Me.Listbox2.Requery
'UnLock controls
txtIIRNumber.Enabled = True
txtIIRNumber.SetFocus
Screen.MousePointer = vbDefault
Exit Sub
ErrorHandler:
Screen.MousePointer = vbDefault
Set rstTrumcardII = Nothing
m = MsgBox(Err.Description, vbInformation, "Error Choosing PartNumber to Build")
You are overwriting rowsource on each iteration?![]()
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Can you post what you have as the Row Source property of your combo
If this helped, please click the star at the bottom left of this posting and add to my reputation. Many thanks.
Bob Fitzpatrick
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
There seems to be so much wrong with that code.
- Never use a reserved word for any object (Rowsource).
- This is in 2x (ok, not harmful)
Listbox1.Enabled = True
Listbox2.Enabled = True
- First iteration of your loop creates a sql string which you then create a rs from, then set LOSN, NOS to some number that comes from rs fields. On next iteration, if sql returns a different set of records, you overwrite LOSN, NOS values until in the end, you end up with whatever the last recordset returns. Makes no sense.
- One sets the rowsource property to a table or query name, a sql statement or semicolon separated values. You're setting it to be a number of dots or X's??
You're complicating this with all that code. Can you not base the listbox on a table or query as per post 2?
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
The following command worked on the older version of access:
Listbox2.List(4) = "...."
I assume I cannot use .List(X) anymore to choose the row in the listbox?
This does not work anymore.
The row source is from the if statement in the code above. (I guess I can't use 'rowsource' as a variable as I misinterpreted shown above.)
I set LOSN and NOS variables (shown above) from a Recordset dependent of Listbox1. It works and get the values each time as it cycles down.
Based on these values of LOSN and NOS, I want it to up date Listbox2. (Only one column)
Ex.
Listbox1 ListBox2
PartNumber1 ..
PartNumber2 .
PartNumber3 ....
PartNumber4 ....
PartNumber5 ....
PartNumber6 ....
I wonder if Bob meant to ask what your rowsourcetype property is? If it's not a value list I don't think you can do what you're trying to do. That might be the difference - 1 is a value list, 2 is not?
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Yes, but you are doing it the most complicated way?The following command worked on the older version of access:
Listbox2.List(4) = "...."
I assume I cannot use .List(X) anymore to choose the row in the listbox?
This does not work anymore.
The row source is from the if statement in the code above. (I guess I can't use 'rowsource' as a variable as I misinterpreted shown above.)
I set LOSN and NOS variables (shown above) from a Recordset dependent of Listbox1. It works and get the values each time as it cycles down.
Based on these values of LOSN and NOS, I want it to up date Listbox2. (Only one column)
Ex.
Listbox1 ListBox2
PartNumber1 ..
PartNumber2 .
PartNumber3 ....
PartNumber4 ....
PartNumber5 ....
PartNumber6 ....
If you insist on a value list, perhaps research a little?
https://www.google.com/search?q=repl...hrome&ie=UTF-8
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
see if this helps. I could find nothing that suggests what you say worked before can be done. If you have a reference can you post it?
https://learn.microsoft.com/en-us/of...istbox.additem
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Thank you!!!! Thank you all for your time. I fixed it by subbing in the following:
If LOSN = 0 And NOS = 0 Then Me.Listbox2.AddItem Item:="...." & ", Index:=X"
If LOSN > 0 And NOS = 1 Then Me.Listbox2.AddItem Item:="." & ", Index:=X"
If LOSN > 0 And NOS = 2 Then Me.Listbox2.AddItem Item:=".." & ", Index:=X"
If LOSN > 0 And NOS = 3 Then Me.Listbox2.AddItem Item:="..." & ", Index:=X"
Where X was the line I wanted it on..
Glad to see you have a solution now. Maybe mark this one as solved then?
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.