Results 1 to 12 of 12

Thread: How to use a query for 2 grids?

  1. #1

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98

    How to use a query for 2 grids?

    Gooood morning everyone,

    here's another question from me to break your heads at
    well I gues it's not so hard.

    Here's the situation:

    I've got a beautiful SQL query that loads into a grid. That works fine.
    But I want to use the same query to use it for another grid on the same form. Only this time it needs a little extra. here's the query:

    VB Code:
    1. Dim strSQL As String
    2.  
    3.   Set cn = New ADODB.Connection
    4.   cn.ConnectionString = "Data Source=spijsDB;User ID=spijs;Password=spijs;"
    5.   cn.Open
    6.   Set rs = New ADODB.Recordset
    7.   grdDatagrid2.Refresh
    8.   cn.CursorLocation = adUseServer
    9.   strSQL = "   SELECT  PO.Verstoring, PO.OpdrachtId, PO.Bonnummer, " & _
    10.             "          PO.ReceptId, A.ArtikelNaam, RT.TypeCode, " & _
    11.             "           PO.RetourID, PO.RetourHoeveelheid, " & _
    12.             "           PO.Plandatum, PO.ChargeGewicht, " & _
    13.             "           PO.AantalCharges, PO.AantalGereed, " & _
    14.             "           PO.StartDatumTijd, PO.LotnummerWas, " & _
    15.             "           PO.Bestemming, R.Versie, PO.Status, " & _
    16.             "           PO.Blokkeren, PO.Commentaar, " & _
    17.             "           R.ChargeGewichtKg, R.Datum, PO.ProductCode, " & _
    18.             "           PO.IsOrder, R.NieuwRecept, PO.IsVerwijderd, " & _
    19.             "           PO.OperatorInvoer " & _
    20.             "   From    ReceptType RT, Recepten R, Artikelen A, ProductieOrders PO " & _
    21.             "   WHERE   RT.ReceptTypeId = R.ReceptTypeId (+) and " & _
    22.             "           R.ReceptId = PO.ReceptId (+) and " & _
    23.             "           PO.ReceptId = A.ArtikelId and " & _
    24.             "           PO.IsVerwijderd = 0 " & _
    25.             "           PO.isorder = 1 " & _
    26.             "  ORDER BY PO.Verstoring, PO.OpdrachtId "
    27.   rs.Open strSQL, cn

    And with the second grid it needs PO.isorder = 0 instead of = 1

    Anyone has a solution for this? Or do I just have to make a new query?
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Suggestion:

    create an integer.

    VB Code:
    1. public gridnumber as integer
    2.  
    3. 'now, for grid 1,
    4. gridnumber=0
    5. 'for grid 2,
    6. gridnumber = 2
    7.  
    8. 'this above is a rough idea
    9.  
    10.  
    11. strSQL = "   SELECT  PO.Verstoring, PO.OpdrachtId, PO.Bonnummer, " & _
    12.             "          PO.ReceptId, A.ArtikelNaam, RT.TypeCode, " & _
    13.             "           PO.RetourID, PO.RetourHoeveelheid, " & _
    14.             "           PO.Plandatum, PO.ChargeGewicht, " & _
    15.             "           PO.AantalCharges, PO.AantalGereed, " & _
    16.             "           PO.StartDatumTijd, PO.LotnummerWas, " & _
    17.             "           PO.Bestemming, R.Versie, PO.Status, " & _
    18.             "           PO.Blokkeren, PO.Commentaar, " & _
    19.             "           R.ChargeGewichtKg, R.Datum, PO.ProductCode, " & _
    20.             "           PO.IsOrder, R.NieuwRecept, PO.IsVerwijderd, " & _
    21.             "           PO.OperatorInvoer " & _
    22.             "   From    ReceptType RT, Recepten R, Artikelen A, ProductieOrders PO " & _
    23.             "   WHERE   RT.ReceptTypeId = R.ReceptTypeId (+) and " & _
    24.             "           R.ReceptId = PO.ReceptId (+) and " & _
    25.             "           PO.ReceptId = A.ArtikelId and " & _
    26.             "           PO.IsVerwijderd = 0 " & _
    27.             "           PO.isorder = " & gridnumber & _
    28.             "  ORDER BY PO.Verstoring, PO.OpdrachtId "

    Since I do not know whether this is in some function... I would suggest you create this common integer, and depending upon the grid, just change gridnumber... for example


    private sub grid1load()

    gridnumber = 1
    'call common function
    end sub

    private sub grid2load()
    gridnumber = 0
    'call common function
    end sub


    I hope I am haven't confused you, and what language is that?

  3. #3

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    As you could have seen at 'location', I'm from the Netherlands so the language is Dutch


    Thanks for the help, I'll try what you suggested and let you know if it works or not.


    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    aah. You're welcome, and I hope it works...

  5. #5

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    There is no such thing as Grid_load, so it has to be done at form_load or form_activate (I gues).
    Here's what it looks like now:


    VB Code:
    1. Private Sub Form_Load()
    2.   Dim strSQL As String
    3.   Dim Gridnummer As Integer
    4.      
    5.   Set cn = New ADODB.Connection
    6.   cn.ConnectionString = "Data Source=spijsDB;User ID=spijs;Password=spijs;"
    7.   cn.Open
    8.   Set rs = New ADODB.Recordset
    9.   grdDatagrid2.Refresh
    10.   cn.CursorLocation = adUseServer
    11.   strSQL = "   SELECT  PO.Verstoring, PO.OpdrachtId, PO.Bonnummer, " & _
    12.             "          PO.ReceptId, A.ArtikelNaam, RT.TypeCode, " & _
    13.             "           PO.RetourID, PO.RetourHoeveelheid, " & _
    14.             "           PO.Plandatum, PO.ChargeGewicht, " & _
    15.             "           PO.AantalCharges, PO.AantalGereed, " & _
    16.             "           PO.StartDatumTijd, PO.LotnummerWas, " & _
    17.             "           PO.Bestemming, R.Versie, PO.Status, " & _
    18.             "           PO.Blokkeren, PO.Commentaar, " & _
    19.             "           R.ChargeGewichtKg, R.Datum, PO.ProductCode, " & _
    20.             "           PO.IsOrder, R.NieuwRecept, PO.IsVerwijderd, " & _
    21.             "           PO.OperatorInvoer " & _
    22.             "   From    ReceptType RT, Recepten R, Artikelen A, ProductieOrders PO " & _
    23.             "   WHERE   RT.ReceptTypeId = R.ReceptTypeId (+) and " & _
    24.             "           R.ReceptId = PO.ReceptId (+) and " & _
    25.             "           PO.ReceptId = A.ArtikelId and " & _
    26.             "           PO.IsVerwijderd = 0 and" & _
    27.             "           PO.isorder = " & Gridnummer & _
    28.             "  ORDER BY PO.Verstoring, PO.OpdrachtId "
    29.   rs.Open strSQL, cn
    30.   'isorder wordt handmatig op 1 of op 0 gezet
    31.   Gridnummer = 1
    32.   Set grdDatagrid2.DataSource = rs
    33.   Gridnummer = 0
    34.   Set grdDataGrid1.DataSource = rs
    35.   grdDataGrid1.Refresh
    36.   grdDatagrid2.Refresh

    And this is no succes. I don't get any errors or anything so I hope you can see what I did wrong!


    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Actually, those functions don't exist. I was merely giving you an idea, such as creating a function for that purpose. Try this: um... let me think first ....


    VB Code:
    1. Private Sub Form_Load()
    2.   Dim strSQL As String
    3.   Dim Gridnummer As Integer
    4.      
    5.   Set cn = New ADODB.Connection
    6.   cn.ConnectionString = "Data Source=spijsDB;User ID=spijs;Password=spijs;"
    7.   cn.Open
    8.   Set rs = New ADODB.Recordset
    9.   grdDatagrid2.Refresh
    10.   cn.CursorLocation = adUseServer
    11.  
    12.   rs.Open strSQL, cn
    13.   'isorder wordt handmatig op 1 of op 0 gezet
    14.  
    15.   Set grdDatagrid2.DataSource = getdatastring(1)
    16.  
    17.   Set grdDataGrid1.DataSource = getdatastring(0)
    18.   grdDataGrid1.Refresh
    19.   grdDatagrid2.Refresh
    20.  
    21. end sub
    22.  
    23. Private function getdatastring(gridnumber as integer) as string
    24.  
    25. getdatastring = "   SELECT  PO.Verstoring, PO.OpdrachtId, PO.Bonnummer, " & _
    26.             "          PO.ReceptId, A.ArtikelNaam, RT.TypeCode, " & _
    27.             "           PO.RetourID, PO.RetourHoeveelheid, " & _
    28.             "           PO.Plandatum, PO.ChargeGewicht, " & _
    29.             "           PO.AantalCharges, PO.AantalGereed, " & _
    30.             "           PO.StartDatumTijd, PO.LotnummerWas, " & _
    31.             "           PO.Bestemming, R.Versie, PO.Status, " & _
    32.             "           PO.Blokkeren, PO.Commentaar, " & _
    33.             "           R.ChargeGewichtKg, R.Datum, PO.ProductCode, " & _
    34.             "           PO.IsOrder, R.NieuwRecept, PO.IsVerwijderd, " & _
    35.             "           PO.OperatorInvoer " & _
    36.             "   From    ReceptType RT, Recepten R, Artikelen A, ProductieOrders PO " & _
    37.             "   WHERE   RT.ReceptTypeId = R.ReceptTypeId (+) and " & _
    38.             "           R.ReceptId = PO.ReceptId (+) and " & _
    39.             "           PO.ReceptId = A.ArtikelId and " & _
    40.             "           PO.IsVerwijderd = 0 and" & _
    41.             "           PO.isorder = " & Gridnumber & _
    42.             "  ORDER BY PO.Verstoring, PO.OpdrachtId "
    43.  
    44. end function



    there. hope that helps. do tell me.. we'll work it out

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    wait! mistake!!

    gimme a couple minz

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    OK, I apologize for misleading you earlier.

    You're going to have to open TWO recordsets.

    Don't get mad at me. I've already been criticized for being an ******* today. So... two recordsets. It's not possible to modify a recordset query without closing and reopening it. I suggest two recordsets

    So, basically, whatever you said in the last sentence of your post was right. New query. Would u like me to help you there?

    Sorry, and hth... damn. bad day today.

  9. #9

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    So basicly I have to define the SQL query 2 times with the adjustment? And there is no (easy) way to do it with only one?


    WiseGuy

    B.T.W. I'm not mad at you, why should I? I'm glad someone takes the time to help me out!
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. dim rs1 as adodb.recordset
    2. dim rs2 as adodb.recordset
    3.  
    4.  
    5. Private Sub Form_Load()
    6.   Dim strSQL As String
    7.   Dim Gridnummer As Integer
    8.      
    9.   Set cn = New ADODB.Connection
    10.   cn.ConnectionString = "Data Source=spijsDB;User ID=spijs;Password=spijs;"
    11.   cn.Open
    12.  
    13.   Set rs1 = New ADODB.Recordset
    14.   set rs2 = new adodb.recordset
    15.  
    16.   grdDatagrid2.Refresh
    17.   cn.CursorLocation = adUseServer
    18.  
    19.   rs1.Open getdatastring(0), cn
    20. rs2.open getdatastring(1),cn
    21.   'isorder wordt handmatig op 1 of op 0 gezet
    22. 'knuut naarf!  :D
    23.  
    24.   Set grdDatagrid2.DataSource = rs1
    25.  
    26.   Set grdDataGrid1.DataSource = rs2
    27.  
    28. msgbox("KnuutZaarf!  Hahaha! ")
    29.  
    30.  
    31.   grdDataGrid1.Refresh
    32.   grdDatagrid2.Refresh
    33.  
    34.  
    35.  
    36. end sub
    37.  
    38.  
    39.  
    40. Private function getdatastring(gridnumber as integer) as string
    41.  
    42. getdatastring = "   SELECT  PO.Verstoring, PO.OpdrachtId, PO.Bonnummer, " & _
    43.             "          PO.ReceptId, A.ArtikelNaam, RT.TypeCode, " & _
    44.             "           PO.RetourID, PO.RetourHoeveelheid, " & _
    45.             "           PO.Plandatum, PO.ChargeGewicht, " & _
    46.             "           PO.AantalCharges, PO.AantalGereed, " & _
    47.             "           PO.StartDatumTijd, PO.LotnummerWas, " & _
    48.             "           PO.Bestemming, R.Versie, PO.Status, " & _
    49.             "           PO.Blokkeren, PO.Commentaar, " & _
    50.             "           R.ChargeGewichtKg, R.Datum, PO.ProductCode, " & _
    51.             "           PO.IsOrder, R.NieuwRecept, PO.IsVerwijderd, " & _
    52.             "           PO.OperatorInvoer " & _
    53.             "   From    ReceptType RT, Recepten R, Artikelen A, ProductieOrders PO " & _
    54.             "   WHERE   RT.ReceptTypeId = R.ReceptTypeId (+) and " & _
    55.             "           R.ReceptId = PO.ReceptId (+) and " & _
    56.             "           PO.ReceptId = A.ArtikelId and " & _
    57.             "           PO.IsVerwijderd = 0 and" & _
    58.             "           PO.isorder = " & Gridnumber & _
    59.             "  ORDER BY PO.Verstoring, PO.OpdrachtId "
    60.  
    61. end function


    THERE!!!

    that should be it!

  11. #11

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    Thanks for the code, that did work! Sorry it took a while to figure that out but I am adjusting an exciting program so there where about 500 lines I had to go through!



    Thanks,

    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    NP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width