?
Solved

Query builder with data control

Posted on 1998-08-25
10
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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 280 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

764 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