I also use the same code within my main form navigation to display the current record "x of y" for the activities.
I have changed the declared variables and ensured there is no conflict in other areas by simply adding a 2 to the end for example rst2 in my sub form and rst in my main form.
The problem I am having is when I load up my main form and navigate to the last record, which should then create a blank new record I get an error in the following code which is attached to my sub form navigation (subfrmCosts):
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Current()
- 'Provide record counter for costs
- Dim rst2 As DAO.Recordset
- Dim lngCount2 As Long
- Set rst2 = Me.RecordsetClone
- With rst2
- .MoveFirst
- .MoveLast
- lngCount2 = .RecordCount
- End With
- 'Show the results of the count
- If Me.CurrentRecord > lngCount2 Then
- Me.txtCostRecNo = "New Cost"
- Else
- Me.txtCostRecNo = "Cost " & Me.CurrentRecord & " of " & lngCount2
- End If
- End Sub
The error is highlighted on the line .MoveLast and I get an alert showing "Run time error 3021" No current record.
I thought I would have stopped this error occuring by adding the if function so that it would display "New Cost" however this doesnt seem to be working, eventhough yesterday everything was running fine.
Any help appreciated thanks.