If you get stuck in VBA, it gets a little rude. One way is to have a form with a timer in it (you can open it invisibly. The timer can check the table, say, once a minute (or any suitable interval) to change the number of records and check the table still exists (code below)
But personally, I do not recommend doing this. Access is known as corruption. When used as a simple back, you are pretty safe most of the time, but to start the monitor means that the file is always open. This is basically a Russian roulette game with your database. At a minimum, I would contact your database from another Access file and track the related tables, so if your monitor fails, you do not bring a production database with you. Finally, make sure you don't request too often, as I would not want you to be the only reason for the website timeout :)
Option Explicit Private m_lngLstRcrdCnt_c As Long Private Sub Form_Open(Cancel As Integer) Const lngOneMinute_c As Long = 60000 Me.TimerInterval = lngOneMinute_c End Sub Private Sub Form_Timer() Const strTblName_c As String = "Foo" Const strKey_c As String = "MyField1" Dim rs As DAO.Recordset Dim lngRcrdCnt As Long If TableExists(strTblName_c) Then Set rs = CurrentDb.OpenRecordset("SELECT Count(" & strKey_c & ") FROM " & strTblName_c & ";", dbOpenSnapshot) If Not rs.EOF Then lngRcrdCnt = Nz(rs.Fields(0&).Value, 0&) rs.Close If lngRcrdCnt <> m_lngLstRcrdCnt_c Then m_lngLstRcrdCnt_c = lngRcrdCnt 'Number of records changed, do something. End If Else 'Table is deleted, do something. m_lngLstRcrdCnt_c = -1 End If End Sub Private Function TableExists(ByVal name As String) As Boolean Dim tdf As DAO.TableDef On Error Resume Next Set tdf = CurrentDb.TableDefs(name) If LenB(tdf.name) Then 'Cheap way to catch broken links. Set SafeGetTable = tdf End If End Function
source share