For some time I have been trying to get a solution to creating a record number (displayed in a field) which does not use autonumber. To date with little luck. I have come accross this code which seems to meet my needsd but I get a Type Mismatch box:
On my form I have an unbound text box called txtPosition.
In the OnCurrent event procedure I have the following code:
---------------------------------------------------------------------------------------------------------------------------------
Private Sub Form_Current()
On Error GoTo Err_Form_Current
Dim rst As Recordset
Set rst = Me.RecordsetClone
rst.Bookmark = Me.Bookmark
Me.txtPosition = rst.AbsolutePosition + 1
Exit_Form_Current:
Set rst = Nothing
Exit Sub
Err_Form_Current:
If Err = 3021 Then 'No current record
Me.txtPosition = rst.RecordCount + 1
Else
MsgBox Error$, 16, "Error in Form_Current()"
End If
Resume Exit_Form_Current
End Sub
------------------------------------------------------------------------------------------------------------------------
What I want is that a new number for each record that increments by 1. Why do I get a type mismatch and can any say how I can either get this to work or another solution.
Many thanks
On my form I have an unbound text box called txtPosition.
In the OnCurrent event procedure I have the following code:
---------------------------------------------------------------------------------------------------------------------------------
Private Sub Form_Current()
On Error GoTo Err_Form_Current
Dim rst As Recordset
Set rst = Me.RecordsetClone
rst.Bookmark = Me.Bookmark
Me.txtPosition = rst.AbsolutePosition + 1
Exit_Form_Current:
Set rst = Nothing
Exit Sub
Err_Form_Current:
If Err = 3021 Then 'No current record
Me.txtPosition = rst.RecordCount + 1
Else
MsgBox Error$, 16, "Error in Form_Current()"
End If
Resume Exit_Form_Current
End Sub
------------------------------------------------------------------------------------------------------------------------
What I want is that a new number for each record that increments by 1. Why do I get a type mismatch and can any say how I can either get this to work or another solution.
Many thanks