Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a list of table fieldnames in a multiple choice listbox. How can I make a query to produce all the table data from the selected fieldnames? Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='ZOR' post='763831' date='06-Mar-2009 11:29']I have a list of table fieldnames in a multiple choice listbox. How can I make a query to produce all the table data from the selected fieldnames? Thanks[/quote]
    Something like this (air code):
    Code:
    Dim varItm As Variant
    Dim strSQL As String
    Dim strFields As String
    
    For Each varItm In Me.Listbox.ItemsSelected
      strFields = strFields & ", " & Me.ListBox.ItemData(varItm)
    Next varItm
    
    If strFields = "" Then
      MsgBox "No fields selected!", vbExclamation
      Exit Sub
    End If
    
    strSQL = "SELECT " & Mid(strFields, 3) & " FROM tblSomething"
    
    CurrentDb.QueryDefs("qryPredefined").SQL = strSQL
    (Needs a reference to the Microsoft DAO 3.6 Object Library)

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks Hans, you were quick. Perfect, best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •