Mike Krailo
Well-known member
- Local time
- Yesterday, 22:15
- Joined
- Mar 28, 2020
- Messages
- 1,342
Not sure what happened with my previous attempt to post this but I'll put it in again. I have attached a sample database that illustrates the problem I am trying to solve. This is a main form with a tab control on it. On a tab is a single subform and the goal is to update the Caption of the tab so it shows the record count in real time when records are added or deleted.
Adding new records seems to work, but when they are deleted, the record count does not decrement. Its like an order of events issue, but I'm not seeing it.
UPDATE: I figured it out. I was on the right track but got distracted. I ended up changing the delete button from a macro to vba and just calling my sub DoCount from there after the delete and it works now. It still won't work if a user clicks the record selector and then deletes it though.
I'm calling this in the forms current event:
Adding new records seems to work, but when they are deleted, the record count does not decrement. Its like an order of events issue, but I'm not seeing it.
UPDATE: I figured it out. I was on the right track but got distracted. I ended up changing the delete button from a macro to vba and just calling my sub DoCount from there after the delete and it works now. It still won't work if a user clicks the record selector and then deletes it though.
I'm calling this in the forms current event:
Code:
Public Sub DoCount()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim StrSQL As String
On Error GoTo ErrorHandler
StrSQL = "SELECT Account.PID, Account.Account, Account.Password, Account.CustID " _
& "FROM Account " _
& "WHERE Account.CustID=" & Nz(Forms!Customer!CustID, 0)
Set db = CurrentDb
Set rs = db.OpenRecordset(StrSQL)
rs.MoveLast
TempVars!RecCount = rs.RecordCount
rs.Close
Set rs = Nothing
Forms!Customer!TabControl.Pages("Pass").Caption = "Passwords(" & TempVars!RecCount & ")"
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 3021 'No Current Record
TempVars!RecCount = 0
Forms!Customer!TabControl.Pages("Pass").Caption = "Passwords(" & TempVars!RecCount & ")"
Exit Sub
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Oops, we found an ERROR"
Resume Next
End Select
End Sub
Attachments
Last edited: