Solved

Query builder with data control

Posted on 1998-08-25
10
159 Views
Last Modified: 2010-04-30


I will have a listbox or some other control that will have all the fields of a query.  I want the users to be able to choose the fields they want, then those fields will be the fields in the dbgrid1.  

In other words, if query 1 has 40 fields and the user chooses only 3 from the listbox then dbgrid1 will have only those 3 fields.  I don't want the DBGrid to show blank columns.  I need good instructions on how to do this.  

Please leave a message if you need clarification.
0
Comment
Question by:DAVIDH
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430915
If you need more help email to shay@hili.com

Private Sub cmdFillDbGrid_Click()
MSFlexGrid1.Rows = 8    ' Set rows and columns.
MSFlexGrid1.Cols = 5

'MSFlexGrid1.Text = "There"

For I = 0 To 3
    For J = 0 To List1(I).ListCount - 1
        If List1(I).Selected(J) Then
            MSFlexGrid1.Col = 0
            MSFlexGrid1.Row = J
            MSFlexGrid1.Text = I & J
        End If
    Next J
Next I

End Sub

0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430916
I have use MSFlexGrid instad of DbGrid.
This works.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430917
Correction.

Private Sub cmdFillDbGrid_Click()
MSFlexGrid1.Rows = 6
MSFlexGrid1.Cols = 5
Dim CountRow

For I = 0 To 3
    For J = 0 To List1(I).ListCount - 1
        If List1(I).Selected(J) Then
            MSFlexGrid1.Col = 0
            CountRow = CountRow + 1
            MSFlexGrid1.Row = CountRow  '*** just the selected will be on the grid.
            MSFlexGrid1.Text = I & J
        End If
    Next J
Next I

End Sub

0
 

Author Comment

by:DAVIDH
ID: 1430918
I do appreciate your response, but it still doesn't work i get the same error message.  What I am looking for:

lets say I have 7 items in a list box.  I want the dbgrid or msflexgrid to only show those 7 items (the dbgrid is tied to an access table the access table may have 30 fields, I only want the fields in the listbox)

thanks
0
 

Expert Comment

by:nbishop
ID: 1430919
Simply use the visible property for each column in the grid you want (or don't want) displayed.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DAVIDH
ID: 1430920
Thanks for the suggestion, but my problem is, I have to do this at run time, The user is going to select certain fields, it has to be automatic.  If you have a sample of how to do this at runtime let me know.

Thanks
0
 
LVL 4

Accepted Solution

by:
mcix earned 140 total points
ID: 1430921
As nbishop suggested, you can accomplish the desired result by using the visible property of the column object...

This ONLY works with a DBGrid and has a limitation!

Private Sub cmdSetVisibleInGrid_Click()
' Where lstQueryFields = Your List Box with the Field Names
' And dbgData = Your DBGrid
' Using this code, the Index of each Item in the list box
' would have to match the Column Number in the DBGrid

Dim mlngCurrentListEntry As Long

    For mlngCurrentListEntry = 0 To lstQueryFields.ListCount - 1
        If lstQueryFields.Selected(mlngCurrentListEntry) Then
            dbgData.Columns(mlngCurrentListEntry).Visible = True
        Else
            dbgData.Columns(mlngCurrentListEntry).Visible = False
        End If
    Next
   
End Sub
0
 
LVL 4

Expert Comment

by:mcix
ID: 1430922
I failed to mention that you should have Multi-Select set to true for the ListBox control...

But you probably already knew that.
0
 

Expert Comment

by:nbishop
ID: 1430923
In an effort to redeem myself, here is a very brief snippet of code to place in the...doubleClick section?...of your list control.  I will dynamically remove colums from the grid with the same name as the columns in the list control.  The caption property of the grid (DBGrid) is case sensitive, so you should use some function like UCase to get around that.  I have not tried this with TrueGrid, but I would imagine that the same should work.  Hope this helps.

    Dim c As Column
    For Each c In DBGrid1.Columns
        If List1.List(List1.ListIndex) = c.Caption Then
        c.Visible = False
        End If
    Next
0
 

Expert Comment

by:nbishop
ID: 1430924
In an effort to redeem myself, here is a very brief snippet of code to place in the...doubleClick section?...of your list control.  I will dynamically remove colums from the grid with the same name as the columns in the list control.  The caption property of the grid (DBGrid) is case sensitive, so you should use some function like UCase to get around that.  I have not tried this with TrueGrid, but I would imagine that the same should work.  Hope this helps.

    Dim c As Column
    For Each c In DBGrid1.Columns
        If List1.List(List1.ListIndex) = c.Caption Then
        c.Visible = False
        End If
    Next
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 36
using Access 8 59
Protecting vb6 & .Net code Obfuscation 18 99
Can we place a tooltip on the actual vb6 form 5 36
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now