List Box HELP!!

  • Thread starter Thread starter Fundays
  • Start date Start date
F

Fundays

Guest
Hi,
I have 2 list boxes on my form. List1 has 7 values (which are the field names of a table) and what ever values the user selects, goes into list2. Now when I click the ShowQuery Button, I want to build a dynamic query using all the field names in list2. Meaning, the user does not have to SELECT anything from list2. The query has to be built dynamically, taking all the values from List2.
How do I use ALL the values in a list box without "selecting" any of them???

List2.ItemsSelected doesn't work because I'm not "selecting" anything from the list box.

List2.ItemData doesn't work either because the List2's Row Source Type is Value list. (If it is set to field list then I cannot transfer the selected items from List1 using List2.addItem)
---Hope I haven't confused you! But hope someone can help me with this asap! :(
 
why don't you use the ItemSelected collection from the first listbox?
 
Fundays,

I don't see the need for the 2nd listbox. The code below will give you
something like --> "Select Field1, Field2, Field3"

Code:
Dim i As Long
Dim strSelect As String

strSelect = ""
For i = 0 To Me.List1.RowCount - 1
    If Me.List1.ItemSelected Then
       If Len(strSelect) = 0 Then
          strSelect = "Select " & Me.List1.ItemData(i)
       Else
          strSelect = strSelect & ", " & Me.List1.ItemData(i)
       End If
    End If
    Next i

Wayne
 
Had a play and this bit of code may help. It returns the Select: Value, Value, etc from items selected in a list box.

Code:
    Dim varItm As Variant
    Dim strSelect, strValue As String
    strSelect = ""
    
    For Each varItm In Me.List1.ItemsSelected
       
            strSelect = strSelect & " " & Me.List1.Column(0, varItm) & ", "
        
    Next varItm
    strValue = "Select: " & strSelect
    Me.txtString.Value = Left(strValue, Len(strValue) - 2)

Hope it helps, let us know how you get on :)
 
just had the same issue. saw in the bible. "Access 2002 Desktop Developer's Handbook" by litwin, getz, and gunderloy the best book.

what you do is you need to use the getstring. so its MyRecordset.getstring

i will copy past a small part of my code:
Dim varMyQuery as variant......

rs1.MoveFirst ' i needed this. i had a loop take it to EOF
varMyQuery = "Facility;Department;Regular Hours;OT Hours;Percentage;WeekStart;" ' these are my headers. not shown in book, my own creation.
varMyQuery = varMyQuery & rs1.GetString(adClipString, ColumnDelimeter:=";", RowDelimeter:=";")
Me.lstWeeklyOTQry.RowSource = varMyQuery

What i am looking for now is a way to format these columns. i need the numbers to be Format(,"#.00") anybody with any ideas on topic???????

thanks,

sam
 

Users who are viewing this thread

Back
Top Bottom