ACC2000: How to Display Line Numbers on Subform RecordsID: Q210340
|
This article shows you how to create and use a procedure to display the
current line or row number in a subform.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
The following examples demonstrate how to create and use the sample
function, GetLineNumber().
NOTE: The sample code in this article uses Microsoft Data Access
Objects. For this code to run properly, you need to reference
the Microsoft DAO 3.6 Object Library.
Option Explicit
Function GetLineNumber (F As Form, KeyName As String, KeyValue)
Dim RS As DAO.Recordset
Dim CountLines
On Error GoTo Err_GetLineNumber
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
=GetLineNumber(Form,"ID",[ID])
Field Name: ID
Data Type: AutoNumber
This field will serve as the required single unique field for the table.
Name: LineNum
ControlSource: =GetLineNumber([Form], "ID", [ID])
Additional query words:
Keywords : kbusage kbdta AccCon FmsSubf
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 13, 1999