• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

pulling data from SQL2K using VB6 checkboxes

I've got a form with 3 check boxes. Any of these check boxes can be checked or unchecked at any time in any combination. I also have a button on this form. During runtime, when the user checks or unchecks the check boxes, and then clicks the button, I want another form to open. On this form I will have a datagrid. The data pulled from the DB will be based off of the user selections from the check boxes on the previous form. How do I do this?
0
Mike Miller
Asked:
Mike Miller
  • 4
  • 3
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Can you explain a little more of what you are trying to achieve ?
Do the checkboxes control the data that is retrieved, or the tables the data comes from ?

You can access the values/states of the checkboxes on one form from another form, so that is not a problem.
0
 
Mike MillerSoftware EngineerAuthor Commented:
Yes the checkboxes will determine what data is pulled. For example, If check1 is checked by the user, Column1 will be displayed in the second form's datagrid

0
 
Carl TawnSystems and Integration DeveloperCommented:
So, you probably need something a little like:

    Dim sColumns As String
    Dim sSQL As String

    If frm1.CheckBox1.Value = vbChecked Then
        sColumns = "FirstName,"
    End If

    If frm1.CheckBox2.Value = vbChecked Then
        sColumns = sColumns & "LastName,"
    End If

    If frm1.CheckBox3.Value = vbChecked Then
        sColumns = sColumns & "Address,"
    End If

    If Len(sColumns) > 0 Then

        sColumns = Left(sColumns, Len(sColumns) - 1)      '// Remove trailing comma

        sSQL = "SELECT " & sColumns & " FROM YourTable"
        YourConnection.Execute(sSQL)

    Else
        '// None of the checkboxes are checked
    End If


Obviously you would need to alter this a bit to match your column and checkbox names, but it should at least demonstrate the principal.

Hope this helps.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Mike MillerSoftware EngineerAuthor Commented:
What do "FirstName" "LastName" etc. represent? Are those column names?
0
 
Carl TawnSystems and Integration DeveloperCommented:
Yes. If you want you checkboxes to control which columns are requested then the sample is on eway of doing it.
0
 
abbdanCommented:
Why not have the button click event build a querystring based on selected checkbox options using case select and then populate the source control of your datagrid with the built querystring?
0
 
abbdanCommented:
Heres some sample suedo code to give you an idea of what I saying:

Select Case CStr(check1 & check2 & check3)
          Case "TrueTrueTrue"
                  QString="SELECT Column1 from MyTable"
          Case "TrueTrueFalse"
                  QString="SELECT Column2 from MyTable"
          Case "TrueFalseTrue"
                  QString="SELECT Column3 from MyTable"
          Case "TrueFalseFalse"
                  QString="SELECT Column4 from MyTable"
          Case "FalseTrueTrue"
                  QString="SELECT Column5 from MyTable"
          Case "FalseTrueFalse"
                  QString="SELECT Column6 from MyTable"
          Case "FalseFalseTrue"
                  QString="SELECT Column7 from MyTable"
          Case "FalseFalseFalse"
                  QString="SELECT Column8 from MyTable"
End Select

form2.mydatagrid.rowsource = QString
0
 
Mike MillerSoftware EngineerAuthor Commented:
I've been playing around with this Select Case but I can't seem to get it. Where do I put the connection? Can you give me some more detail as to what goes on what form?
0
 
abbdanCommented:
That was just an example of suedo code.  I'd have to have more information to give you exact code.  I need to know your second forms name and your datagrids name to give you the exact connection assignment statement.  You may also need to include semicolons at the end of each Select statement.  The goal is to get that query string into your datagrid so that the results of the datagrid reflect the querystring contents.
0
 
Mike MillerSoftware EngineerAuthor Commented:
Ok here's a little more detail...

On one form (frmCustomReport) I have the following check boxes:
chkStock
chkOther

chkPartNumber
chkQuantity
chkCost
chkKardex
chkLocation
chkTeam
chkTag

chkPartNumber2
chkLocation2

Then there will be 2 other forms. When the button is clicked on frmCustomReport and chkStock is checked frmCustomStockReport will display. If chkOther is checked on frmCustomReport, then frmCustomOtherReport will display.

If frmCustomStockReport is displayed then I want to show all of the columns that are checked in the second set of check boxes from a table called Main from the database PhysicalInventory.

If frmCustomOtherReport is displayed then I want to show all of the columns that are checked in the second set of check boxes from a table called MainWIP from the database PhysicalInventory.

The database tables are as follows:

Main:
PART_NUMBER
Quantity
Cost
Location
Team
Tag

MainWIP:
PART_NUMBER
Quantity
Cost
Location
Team
Tag

The third set of checkboxes will just be used to determine the "order by" clause in the statement. So if chkPartNumber2.value = vbChecked then ORDER BY PART_NUMBER will be included in the query.

0

Featured Post

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!

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now