Results 1 to 4 of 4

Thread: [RESOLVED] Having a 'max' issue

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] Having a 'max' issue

    I have this code, which works: tmpBOL is incremented
    VB Code:
    1. 'find the next available number
    2. '=====================================
    3. Set rsBOLHeader = New ADODB.Recordset
    4. '=====================================
    5. sql = "SELECT [BOL] FROM BOLHEADER ORDER BY [BOL]"
    6. rsBOLHeader.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
    7. If Not rsBOLHeader.BOF And Not rsBOLHeader.EOF Then
    8.     rsBOLHeader.MoveLast
    9.     tmpBOL = rsBOLHeader![bol] + 1
    10. End If
    11. rsBOLHeader.Close
    12. Set rsBOLHeader = Nothing
    13. '=========================

    However, when I do this, tmpBOL is always 1.
    VB Code:
    1. 'find the next available number
    2. Dim lastbol As Long
    3. '=====================================
    4. Set rsBOLHeader = New ADODB.Recordset
    5. '=====================================
    6. sql = "SELECT max([BOL]) as lastBOL FROM BOLHEADER "
    7. rsBOLHeader.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
    8. tmpBOL = lastbol + 1
    9. rsBOLHeader.Close
    10. Set rsBOLHeader = Nothing
    11. '=========================

    Obviously a syntax error, but my documentation doesn't clear it up for me.

    I'm trying to 'optimize' some code by doing away with unecessary loops.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Having a 'max' issue

    the lastbol variable you have isn't affected by the SQL at all...
    VB Code:
    1. tmpBOL = rsBOLHeader.Fields("lastBOL").Value + 1

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Having a 'max' issue

    That worked. I have to "digest" it a bit. I really didn't notice any difference in the speed of the data fetching. Is it basically doing the same thing (behind the scenes) in either case?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Having a 'max' issue

    The ONLY difference is that you used the value of a local variable named lastbol, while Bush used the value of the field in recordset rsBOLHeader named lastBOL. There's no difference in how long it takes to fill the recordset, because the code is the same (rsBOLHeader.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText) in both cases.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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