I have a form in MS Access with a Tab Control (called TabCtrl
). This control has several pages, each with a subform.
On Form_Open
, I want to query the subforms for the total number of records and put that number in the tab's name. For example, the tab named MyTab should become MyTab (2):
Private Sub SetTabName_MyTab()
Dim i As Integer
i = CurrentDb.OpenRecordset("Select count(*) from [MyQry];").Fields(0).Value
TabCtrl.Pages("MyTab").Name = "MyTab (" & i & ")"
End Sub
However, when I run this, the last line returns Run-time error 2136 "To set this property, open the form or report in Design view". Does this mean I can't do this in code? Should I use another Event?