Hi Folks,
I have the following function on a Access 2000 based system:
Function fncstrIdentifierNumber(strFuncIdentifierDate As String, strFuncIdentifierType As String) As String
On Error GoTo Err_fncstrIdentifierNumber
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim dblRecordCount As Double
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.Open "SELECT * FROM tblTransmittal WHERE [fldstrTransmittalIdentifier] like '" & strFuncIdentifierDate & strFuncIdentifierType & "*';"
Select Case rst.RecordCount
Case Is < 1
fncstrIdentifierNumber = "00"
Case Is < 10
fncstrIdentifierNumber = "0" & CStr(rst.RecordCount)
Case Else
fncstrIdentifierNumber = CStr(rst.RecordCount)
End Select
rst.Close
Set rst = Nothing
Exit_fncstrIdentifierNumber:
Exit Function
Err_fncstrIdentifierNumber:
MsgBox Err.Description
Resume Exit_fncstrIdentifierNumber
End Function
The function above is used to determine the next and a sequential number of an identifier of a transmittal sheet to be sent to the main office. As you can see the date (YYYYMMDD) and type are both parameters of the Function.
The number of identifiers of the same type in the same date determines the next one (up to 99) in the sequence.
Now the strange part (at least to me) rst.recordcount returns ZERO. Always! If I get the SQL expression and build a new query based on that expression it returns the right number of records (I tried with different days and types, always correct).
What am I missing? (Besides my mind, naturally )
Luciano R. Humberto
IT Specialist - Support I
The Ryan Companies
I have the following function on a Access 2000 based system:
Function fncstrIdentifierNumber(strFuncIdentifierDate As String, strFuncIdentifierType As String) As String
On Error GoTo Err_fncstrIdentifierNumber
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim dblRecordCount As Double
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.Open "SELECT * FROM tblTransmittal WHERE [fldstrTransmittalIdentifier] like '" & strFuncIdentifierDate & strFuncIdentifierType & "*';"
Select Case rst.RecordCount
Case Is < 1
fncstrIdentifierNumber = "00"
Case Is < 10
fncstrIdentifierNumber = "0" & CStr(rst.RecordCount)
Case Else
fncstrIdentifierNumber = CStr(rst.RecordCount)
End Select
rst.Close
Set rst = Nothing
Exit_fncstrIdentifierNumber:
Exit Function
Err_fncstrIdentifierNumber:
MsgBox Err.Description
Resume Exit_fncstrIdentifierNumber
End Function
The function above is used to determine the next and a sequential number of an identifier of a transmittal sheet to be sent to the main office. As you can see the date (YYYYMMDD) and type are both parameters of the Function.
The number of identifiers of the same type in the same date determines the next one (up to 99) in the sequence.
Now the strange part (at least to me) rst.recordcount returns ZERO. Always! If I get the SQL expression and build a new query based on that expression it returns the right number of records (I tried with different days and types, always correct).
What am I missing? (Besides my mind, naturally )
Luciano R. Humberto
IT Specialist - Support I
The Ryan Companies