Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

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?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of Member_2_1242703
Member_2_1242703

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What do "FirstName" "LastName" etc. represent? Are those column names?
Yes. If you want you checkboxes to control which columns are requested then the sample is on eway of doing it.
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?
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
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?
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.
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.