Solved

Query builder with data control

Posted on 1998-08-25
10
162 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 89
maro to copy and paste from one worksheet to another based on a condition 11 57
Add a task in Outlook from access 11 42
Advice in Xamarin 21 97
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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