Results 1 to 24 of 24

Thread: Multiple SQL record display

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Multiple SQL record display

    I have created a program that allows users to enter a sales order number, and obtain tracking info from a database... I am using SQL to perform this.... However, some sales order numbers have multiple boxes and/or shipments, and I am not sure how to first get ALL the records, and second display each record discretely....

    Can anyone assist me?

    Thanks in advance..........

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    I don't know how you are displaying them now, but it would appear, at least on the surface, that a listbox or listview might be appropriate in displaying the information for those orders that have multiple whatevers.

    How are you displaying the data now?

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    About 75% of the orders are single shipments, so I got 'em going to various text boxes and labels...I've attached the form

    I've set a variable = to the record count, but it's only bringing back 1 record, when I know there are more....
    Attached Images Attached Images  

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    About 75% of the orders are single shipments, so I got 'em going to various text boxes and labels...

    I've set a variable = to the record cound, but it's only bringing back 1 record, when I know there are more....
    It sounds like you are going to have to take that variable count off, and switch from textboxs to a control that can display multiple entries. Granted, 75% of the returns will be single entries, but you need the mutiple entry controls for the other 25%.

    Between a grid, or a listbox or a listview or a whatever is a decision you need to make based on how you want your screen to look and your application requirements.

    You have some real estate on that screen, so changing controls shouldn't be a big deal.

    Nice screen BTW!

  5. #5

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Ok, cool... Do you know the SQL command to bring back the multiple records?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Ok, cool... Do you know the SQL command to bring back the multiple records?
    You would use your garden variety SELECT statement. It will bring back everything it finds that matches your WHERE clause and/or any joins you have regardless of whether it is one record or one hundred and one records.

  7. #7

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Ok, I'm an intermediate SQL user.... This is what I have at present:

    VB Code:
    1. ConnectDatabase
    2.        
    3.         strSQL = "SELECT * " & _
    4.         "FROM LAWSON_BSACLIPTRK " & _
    5.         "Where LAWSON_BSACLIPTRK.ORDER_NBR = " & txtSOEntry
    6.  
    7.     Set rsLAWSON_BSACLIPTRK = dbResourceLocatorDatabase.OpenRecordset(strSQL, dbOpenDynaset)

    How does the SELECT you metioned look?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Looks fine to me. Does it work is the important question.

    Are you going to use a ListBox or Listview? From what little I know of your app, I would think a Listbox would involve the least amount of coding.

  9. #9

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Well, the SQL works, but I'm only getting 1 record... As for the data, I'll take your adivce and use the list box....

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Well, the SQL works, but I'm only getting 1 record... As for the data, I'll take your adivce and use the list box....
    Is that because there is only one record associated with the transaction? You said that would be the case 75% of the time.

  11. #11

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Well, I have access to the database, so I purposely selected a sales order number with multiple shipments...

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Well, I have access to the database, so I purposely selected a sales order number with multiple shipments...
    And each shipment is in individual record which all have the exact same txtSOEntry number?

  13. #13

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Yes...

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Yes...
    Well, then stealth, I am a confused Hack

    In your database, is your shipment number stored as a string or a number?

  15. #15
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Well, the SQL works, but I'm only getting 1 record... As for the data, I'll take your adivce and use the list box....
    And what code are you using to determine that you are getting one row returned?

    Only one row will be "presented" by ADO at a time...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  16. #16

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    String... I think what I need is a fetch command, I just keep getting a syntax error...
    Attached Images Attached Images  

  17. #17
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Multiple SQL record display

    How are the controls being filled from that RS?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  18. #18

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    VB Code:
    1. ConnectDatabase
    2.        
    3.         strSQL = "SELECT * FROM LAWSON_BSACLIPTRK " & _
    4.         "Where LAWSON_BSACLIPTRK.ORDER_NBR = " & txtSOEntry
    5.          
    6.     Set rsLAWSON_BSACLIPTRK = dbResourceLocatorDatabase.OpenRecordset(strSQL, dbOpenDynaset)
    7.    
    8.     intShipmentCount = rsLAWSON_BSACLIPTRK.RecordCount
    9.     Debug.Print intShipmentCount
    10.    
    11.         txtTrackingResult = Trim(rsLAWSON_BSACLIPTRK!TRACKING_NBR)
    12.         lstTrackingResult.AddItem (Trim(rsLAWSON_BSACLIPTRK!TRACKING_NBR))
    13.         lblCarrierResult = rsLAWSON_BSACLIPTRK!CAR_NAME
    14.         txtPONumber = Trim(rsLAWSON_BSACLIPTRK!PUR_NBR)
    15.  
    16. '-------------------------------------------------------------------------------------------------
    17.         'Date Conversion
    18.         strYear = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 1, 4)
    19.         strMonth = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 5, 2)
    20.         strDay = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 7, 2)
    21.         strDate = strMonth & "/" & strDay & "/" & strYear
    22.         lblShipDateResult = strDate
    23. '-------------------------------------------------------------------------------------------------
    24.         'Time Conversion
    25.         strHour = Mid(rsLAWSON_BSACLIPTRK!R_TIME, 1, 2)
    26.         strMinute = Mid(rsLAWSON_BSACLIPTRK!R_TIME, 2, 2)
    27.        
    28.         Select Case strHour
    29.        
    30.         Case Is > 12
    31.             strHour = strHour - 12
    32.             strTimeOfDay = " p.m."
    33.            
    34.         Case Is < 12
    35.        
    36.             strTimeOfDay = " a.m."
    37.          
    38.         Case Is = 12
    39.        
    40.             strTimeOfDay = " p.m."
    41.            
    42.         End Select
    43.        
    44.         strTime = strHour & ":" & strMinute & strTimeOfDay
    45.         lblTime = strTime
    46.        
    47. '-------------------------------------------------------------------------------------------------
    48.  
    49.         lblFreightChargeResult = rsLAWSON_BSACLIPTRK!FRT_CHG
    50.         lblFreightChargeResult = "$" & lblFreightChargeResult / 100
    51.         lblFreightChargeResult = Format(lblFreightChargeResult, "Currency")

  19. #19
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Multiple SQL record display

    Here's an example of moving through a recordset:

    Code:
        objCmd.CommandText = "GetAppEle_P"
        objCmd.CommandType = adCmdStoredProc
        
        objCmd.ActiveConnection = gCn
        Set rsTemp = objCmd.Execute
        
        ReDim gEleRoleBits(rsTemp(0), 1 To 2)
        
        Do While rsTemp.EOF = False
            Select Case rsTemp(1)
                Case Is < 33
                    gEleRoleBits(rsTemp(0), 1) = gEleRoleBits(rsTemp(0), 1) Or (2 ^ (rsTemp(1) - 1))
                Case Is < 65
                    gEleRoleBits(rsTemp(0), 2) = gEleRoleBits(rsTemp(0), 2) Or (2 ^ (rsTemp(1) - 33))
            End Select
            rsTemp.MoveNext
        Loop

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  20. #20

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    Ok... I am trying not to loop though.... There are 400,000+ records
    I was looking for the SQL commands....

  21. #21
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Ok... I am trying not to loop though.... There are 400,000+ records
    I was looking for the SQL commands....
    Either you or I are missing the point here.

    The SQL command you execute will return two rows when you specify an ORDER NUMBER that has two records associated with it in the database.

    Then on the VB side you need to move from one row to the next - that's the code I'm showing.

    I would never return 400000 rows in a QUERY and then loop through them

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  22. #22

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Smile Re: Multiple SQL record display

    Oh, I get it I would only be looping through the records the SQL statement brings back.... What a dork...

    Thanks!

    Sorry for the confusion Hack

  23. #23
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Multiple SQL record display

    Quote Originally Posted by stealth black
    Sorry for the confusion Hack
    Actually, I was confused for a while. I was happy to see szlamany step in. So, you got this all settled now?

  24. #24

    Thread Starter
    Registered User
    Join Date
    Jun 2005
    Posts
    87

    Re: Multiple SQL record display

    For the most part... I'm returning the records now, but I want to allow the user to manually select the next record by pressing Next, and it's not doing anything...I get the first record, press next, and it says "No record"...

    VB Code:
    1. Private Sub cmdSOTrack_Click()
    2.  
    3.     'For Testing
    4.     'txtSOEntry = 1666458 '<------ FedEx Test
    5.     txtSOEntry = 1078290 '<------ UPS Test
    6.     'txtSOEntry = 1680136 '<------ USPS Test
    7.     'txtSOEntry = 1666439 '<------ ESTES Test
    8.    
    9.     If txtSOEntry = "" Or txtSOEntry = " " Then
    10.        
    11.         MsgBox "Please enter a PO or Sale Order Number to track", vbOKOnly, "Need A Number"
    12.         txtSOEntry.BackColor = &HC0FFFF
    13.        
    14.     End If
    15.    
    16.     ConnectDatabase
    17.        
    18.         strSQL = "SELECT * FROM LAWSON_BSACLIPTRK " & _
    19.         "Where LAWSON_BSACLIPTRK.ORDER_NBR = " & txtSOEntry
    20.  
    21.     Set rsLAWSON_BSACLIPTRK = dbResourceLocatorDatabase.OpenRecordset(strSQL, dbOpenDynaset)
    22.    
    23.         rsLAWSON_BSACLIPTRK.MoveLast
    24.    
    25.         intShipmentCount = rsLAWSON_BSACLIPTRK.RecordCount
    26.        
    27.     If intShipmentCount > 1 Then
    28.        
    29.         MsgBox "There are " & intShipmentCount &" shipments... Please use the 'Next Record' button to view other shipments", vbOKOnly, "Multiple Shipments"
    30.             cmdNext.Enabled = True
    31.    
    32.     End If
    33.            
    34.         txtTrackingResult = Trim(rsLAWSON_BSACLIPTRK!TRACKING_NBR)
    35.         lblCarrierResult = rsLAWSON_BSACLIPTRK!CAR_NAME
    36.         txtPONumber = Trim(rsLAWSON_BSACLIPTRK!PUR_NBR)
    37.  
    38. '-------------------------------------------------------------------------------------------------
    39.         'Date Conversion
    40.         strYear = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 1, 4)
    41.         strMonth = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 5, 2)
    42.         strDay = Mid(rsLAWSON_BSACLIPTRK!DATE_IN, 7, 2)
    43.         strDate = strMonth & "/" & strDay & "/" & strYear
    44.         lblShipDateResult = strDate
    45. '-------------------------------------------------------------------------------------------------
    46.         'Time Conversion
    47.         strHour = Mid(rsLAWSON_BSACLIPTRK!R_TIME, 1, 2)
    48.         strMinute = Mid(rsLAWSON_BSACLIPTRK!R_TIME, 2, 2)
    49.        
    50.         Select Case strHour
    51.        
    52.         Case Is > 12
    53.             strHour = strHour - 12
    54.             strTimeOfDay = " p.m."
    55.            
    56.         Case Is < 12
    57.        
    58.             strTimeOfDay = " a.m."
    59.          
    60.         Case Is = 12
    61.        
    62.             strTimeOfDay = " p.m."
    63.            
    64.         End Select
    65.        
    66.         strTime = strHour & ":" & strMinute & strTimeOfDay
    67.         lblTime = strTime
    68.        
    69. '-------------------------------------------------------------------------------------------------
    70.  
    71.         lblFreightChargeResult = rsLAWSON_BSACLIPTRK!FRT_CHG
    72.         lblFreightChargeResult = "$" & lblFreightChargeResult / 100
    73.         lblFreightChargeResult = Format(lblFreightChargeResult, "Currency")
    74.  
    75.     If InStr(lblCarrierResult, "UPS") <> 0 Then
    76.        
    77.         imgTrackingViewer.Picture = LoadPicture("C:\Documents and Settings\gstallin\My Documents\Visual Basic Programs\Resource Locator\UPS Package 1" & ".jpg")
    78.         imgESTESPage.Enabled = False
    79.         imgESTESPage.Visible = False And imgESTESPage.Visible = False
    80.         imgUSPSPage.Enabled = False
    81.         imgUSPSPage.Visible = False And imgUSPSPage.Visible = False
    82.         imgFedExPage.Visible = False And imgFedExPage.Visible = False
    83.        
    84.     End If
    85.    
    86.     If InStr(lblCarrierResult, "USPS") <> 0 Then
    87.    
    88.         imgTrackingViewer.Picture = LoadPicture("C:\Documents and Settings\gstallin\My Documents\Visual Basic Programs\Resource Locator\USPS Truck" & ".gif")
    89.         imgUPSPage.Enabled = False
    90.         imgUPSPage.Visible = False And imgUSPSPage.Visible = False
    91.         imgESTESPage.Enabled = False
    92.         imgESTESPage.Visible = False And imgESTESPage.Visible = False
    93.         imgFedExPage.Visible = False And imgFedExPage.Visible = False
    94.        
    95.     End If
    96.    
    97.     If InStr(lblCarrierResult, "ESTES") <> 0 Then
    98.    
    99.         imgTrackingViewer.Picture = LoadPicture("C:\Documents and Settings\gstallin\My Documents\Visual Basic Programs\Resource Locator\Estes" & ".gif")
    100.         imgUPSPage.Enabled = False
    101.         imgUPSPage.Visible = False And imgUPSPage.Visible = False
    102.         imgUSPSPage.Enabled = False
    103.         imgUSPSPage.Visible = False And imgUSPSPage.Visible = False
    104.         imgFedExPage.Visible = False And imgFedExPage.Visible = False
    105.        
    106.     End If
    107.    
    108.     If InStr(lblCarrierResult, "FedEx") <> 0 Then
    109.    
    110.         imgTrackingViewer.Picture = LoadPicture("C:\Documents and Settings\gstallin\My Documents\Visual Basic Programs\Resource Locator\FedEx" & ".jpg")
    111.         imgUPSPage.Enabled = False
    112.         imgUPSPage.Visible = False And imgUPSPage.Visible = False
    113.         imgUSPSPage.Enabled = False
    114.         imgUSPSPage.Visible = False And imgUSPSPage.Visible = False
    115.         imgESTESPage.Visible = False And imgESTESPage.Visible = False
    116.        
    117.     End If
    118.    
    119. EndSub:
    120.  
    121.     'CloseDatabase
    122.    
    123. End Sub
    124.  
    125. Private Sub cmdNext_Click()
    126.     rsLAWSON_BSACLIPTRK.MoveNext
    127.    
    128. End Sub

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