|
-
Feb 22nd, 2007, 03:20 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Having a 'max' issue
I have this code, which works: tmpBOL is incremented
VB Code:
'find the next available number
'=====================================
Set rsBOLHeader = New ADODB.Recordset
'=====================================
sql = "SELECT [BOL] FROM BOLHEADER ORDER BY [BOL]"
rsBOLHeader.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
If Not rsBOLHeader.BOF And Not rsBOLHeader.EOF Then
rsBOLHeader.MoveLast
tmpBOL = rsBOLHeader![bol] + 1
End If
rsBOLHeader.Close
Set rsBOLHeader = Nothing
'=========================
However, when I do this, tmpBOL is always 1.
VB Code:
'find the next available number
Dim lastbol As Long
'=====================================
Set rsBOLHeader = New ADODB.Recordset
'=====================================
sql = "SELECT max([BOL]) as lastBOL FROM BOLHEADER "
rsBOLHeader.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
tmpBOL = lastbol + 1
rsBOLHeader.Close
Set rsBOLHeader = Nothing
'=========================
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]
-
Feb 22nd, 2007, 03:24 PM
#2
Re: Having a 'max' issue
the lastbol variable you have isn't affected by the SQL at all...
VB Code:
tmpBOL = rsBOLHeader.Fields("lastBOL").Value + 1
-
Feb 22nd, 2007, 03:30 PM
#3
Thread Starter
PowerPoster
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]
-
Feb 22nd, 2007, 05:31 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|