I am trying to develop an application that will automatically assign serial numbers. The format is to be WeekNum&MonthNum&2DigitYearNum-(sequential number) The sequential number will be relative to the week number. I have written everything to determine what the serial number should be but I am having a hard time determining the sequential number. Here is my code
Private Function getlastseq(weekno As String) As String
Dim sqlstr As String
Dim weekmatch As String
Dim conntemp As ADODB.Connection
Dim rstemp As New ADODB.Recordset
Dim lastset As String
weekmatch = weekno
Set conntemp = New ADODB.Connection
conntemp.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\semserv3\users\kmaclennan\cubeserial.mdb;" & _
"User ID=Admin;" & _
"Password='';"
sqlstr = "SELECT Max(SN.seq) AS seq1 FROM sn WHERE sn.ser = '" & weekmatch & "' GROUP BY SN.ser;"
rstemp.Open sqlstr, conntemp, 3, 3
If rstemp.RecordCount < 1 Then
getlastseq = "0001"
Else
MsgBox Str(rstemp.RecordCount)
' MsgBox Str(rstemp.Fields(0))
' getlastseq = Str(rstemp.Fields(0))
End If
End Function
The problem that I'm having is that I have 3 records in the table but the query doesn't look beyond the first. The value returned should equal 3 but it equals 1
ser seq ExLot ExJob EmLot EmJob DiLot DiJob
210508- 1 123 123 123 123 123 123
210508- 2 456 456 456 456 456 456
210508- 3 555 555 555 555 555 555
If I take the space prior to the first record out I get 0 records returned
Here is the query string from my locals window
: sqlstr : "SELECT Max(SN.seq) AS seq1 FROM sn WHERE sn.ser = ' 210508-' GROUP BY SN.ser" : String
Private Function getlastseq(weekno As String) As String
Dim sqlstr As String
Dim weekmatch As String
Dim conntemp As ADODB.Connection
Dim rstemp As New ADODB.Recordset
Dim lastset As String
weekmatch = weekno
Set conntemp = New ADODB.Connection
conntemp.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=\\semserv3\users\kmaclennan\cubeserial.mdb;" & _
"User ID=Admin;" & _
"Password='';"
sqlstr = "SELECT Max(SN.seq) AS seq1 FROM sn WHERE sn.ser = '" & weekmatch & "' GROUP BY SN.ser;"
rstemp.Open sqlstr, conntemp, 3, 3
If rstemp.RecordCount < 1 Then
getlastseq = "0001"
Else
MsgBox Str(rstemp.RecordCount)
' MsgBox Str(rstemp.Fields(0))
' getlastseq = Str(rstemp.Fields(0))
End If
End Function
The problem that I'm having is that I have 3 records in the table but the query doesn't look beyond the first. The value returned should equal 3 but it equals 1
ser seq ExLot ExJob EmLot EmJob DiLot DiJob
210508- 1 123 123 123 123 123 123
210508- 2 456 456 456 456 456 456
210508- 3 555 555 555 555 555 555
If I take the space prior to the first record out I get 0 records returned
Here is the query string from my locals window
: sqlstr : "SELECT Max(SN.seq) AS seq1 FROM sn WHERE sn.ser = ' 210508-' GROUP BY SN.ser" : String