S
Stephen
I have an .ADP database and I am having trouble getting the GetLineNumber
function working...
The code is as follows:
On Continuous FormA, I have a field called "LineNumber" with the following
Control Source:
=GetLineNumber([Forms],"OrderID",[OrderID])
Within the code of the form, I have the following function:
Function GetLineNumber(F As Form, KeyName As String, KeyValue)
Dim CountLines
On Error GoTo Err_GetLineNumber
Dim rs As DAO.Recordset
Set rs = F.RecordsetClone
' Find the current record.
Select Case rs.Fields(KeyName).Type
' Find using numeric data type key value.
Case dbInteger, dbLong, dbCurrency, dbSingle, dbDouble, dbByte
rs.FindFirst "[" & KeyName & "] = " & KeyValue
' Find using date data type key value.
Case dbDate
rs.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
' Find using text data type key value.
Case dbText
rs.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
Case Else
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Loop backward, counting the lines.
Do Until rs.BOF
CountLines = CountLines + 1
rs.MovePrevious
Loop
Bye_GetLineNumber:
' Return the result.
GetLineNumber = CountLines
Exit Function
Err_GetLineNumber:
CountLines = 0
Resume Bye_GetLineNumber
End Function
------- QUESTION: I am getting a"0" for every line. Is this because the
recordset is "DAO.Recordset"? Shuold it be something else with an .ADP
file?
Any ideas?
-Stephen
function working...
The code is as follows:
On Continuous FormA, I have a field called "LineNumber" with the following
Control Source:
=GetLineNumber([Forms],"OrderID",[OrderID])
Within the code of the form, I have the following function:
Function GetLineNumber(F As Form, KeyName As String, KeyValue)
Dim CountLines
On Error GoTo Err_GetLineNumber
Dim rs As DAO.Recordset
Set rs = F.RecordsetClone
' Find the current record.
Select Case rs.Fields(KeyName).Type
' Find using numeric data type key value.
Case dbInteger, dbLong, dbCurrency, dbSingle, dbDouble, dbByte
rs.FindFirst "[" & KeyName & "] = " & KeyValue
' Find using date data type key value.
Case dbDate
rs.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
' Find using text data type key value.
Case dbText
rs.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
Case Else
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select
' Loop backward, counting the lines.
Do Until rs.BOF
CountLines = CountLines + 1
rs.MovePrevious
Loop
Bye_GetLineNumber:
' Return the result.
GetLineNumber = CountLines
Exit Function
Err_GetLineNumber:
CountLines = 0
Resume Bye_GetLineNumber
End Function
------- QUESTION: I am getting a"0" for every line. Is this because the
recordset is "DAO.Recordset"? Shuold it be something else with an .ADP
file?
Any ideas?
-Stephen