Solved

Query builder with data control

Posted on 1998-08-25
10
158 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now