Page Numbers on a form

  • Thread starter Thread starter Lonnie
  • Start date Start date
L

Lonnie

Page Numbers on a form without using the navigation
selection. I would like to but it in a text box anywhere
on the form. Can anyone help a beginner.
 
I think you really mean record numbers, pages are something else. And why
don't you want to use the built-in record selection bar?
-Ed
 
It is because I only want the people who use it to view
and not use it as a function. It is a very restrictive
database.
 
Place this code in a new module:

Public Function modCountRecords(F As Form)
On Error GoTo modCountRecords_Err

Dim Rs As Recordset
Set Rs = F.RecordsetClone

Rs.MoveLast
modCountRecords = Rs.RecordCount & " records"
Rs.Close

modCountRecords_Exit:
Exit Function

modCountRecords_Err:
If Err = 3021 Then
modCountRecords = 0 & " records"
Else
MsgBox Err.Description, , "Error #" & Err
End If
Resume modCountRecords_Exit
End Function

Public Function IsNewRecord(F As Form) As Integer
Dim S As String
On Error Resume Next
S = F.Bookmark
IsNewRecord = Err <> 0
End Function

Now on your form place a label and name it RecCount, now add this to
your forms OnCurrent:

Private Sub Form_Current()
If IsNewRecord(Forms!FormName) Then
Me!RecCount.Caption = "New Record"
Else
Me!RecCount.Caption = Forms!FormName.CurrentRecord & " of " &
modCountRecords(Forms!FormName)
End If
End Sub

Replace FormName with your form name.

If using code is not for you then create a textbox and add this to the
ControlSource:

=IIf([ID]="New","New Record",[Forms]![FormName].[CurrentRecord] & " of
" & Count([ID]) & " records")

Replace [ID] with your id field. Also make the default value "New"


Hope this helps.
 
Thanks, worked great.
-----Original Message-----
Place this code in a new module:

Public Function modCountRecords(F As Form)
On Error GoTo modCountRecords_Err

Dim Rs As Recordset
Set Rs = F.RecordsetClone

Rs.MoveLast
modCountRecords = Rs.RecordCount & " records"
Rs.Close

modCountRecords_Exit:
Exit Function

modCountRecords_Err:
If Err = 3021 Then
modCountRecords = 0 & " records"
Else
MsgBox Err.Description, , "Error #" & Err
End If
Resume modCountRecords_Exit
End Function

Public Function IsNewRecord(F As Form) As Integer
Dim S As String
On Error Resume Next
S = F.Bookmark
IsNewRecord = Err <> 0
End Function

Now on your form place a label and name it RecCount, now add this to
your forms OnCurrent:

Private Sub Form_Current()
If IsNewRecord(Forms!FormName) Then
Me!RecCount.Caption = "New Record"
Else
Me!RecCount.Caption = Forms!FormName.CurrentRecord & " of " &
modCountRecords(Forms!FormName)
End If
End Sub

Replace FormName with your form name.

If using code is not for you then create a textbox and add this to the
ControlSource:

=IIf([ID]="New","New Record",[Forms]![FormName]. [CurrentRecord] & " of
" & Count([ID]) & " records")

Replace [ID] with your id field. Also make the default value "New"


Hope this helps.


It is because I only want the people who use it to view
and not use it as a function. It is a very restrictive
database.

.
 
Back
Top