Call a subroutine after record insert

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Hello All,

I have an external application that is going to connect to an access
database and insert a record into a table. Can my access database detect a
record insertion and call a subroutine?

I appreciate the help.
 
Hello All,

I have an external application that is going to connect to an access
database and insert a record into a table. Can my access database detect a
record insertion and call a subroutine?

I appreciate the help.

You mean in the AfterInsert event of a form? Umm... yeah!
 
The direct answer is no, but you can work around that.
The easy part is to be able to know a record has been added. You can add a
hidden form to your application and use the form Timer event to periodically
see how many records are in the table. When the number of records is
increased, you will know a record has been added. The trick; however, is
knowing which record has been added.

Private Sub Form_Timer()
Static lngSaveRecs As Long
Dim lngCurrRecs As Long

lgnCurrRecs = Currentdb.Tabledefs("TheTableName").Recordcount)

Select Case lngSaveRecs
Case 0 'First time through
lngSaveRecs = lngCurrRecs
Case < lngCurrRecs 'Records have been deleted
lngSaveRecs = lngCurrRecs
Case > lngCurrRecs 'Record or Records have been added
Call YouSubRoutine
End Select
 
Phil said:
If I use Klatuu's trick which is to use a form timer, how do I execute
this
form.

You need to have Access running somewhere so this form can be loaded as
a hidden form. Search these access newsgroups for references to opening
a form at startup ... there's a lot of discussion already in the
archives.

Google Groups is a good way to search the Access archives.
 
Back
Top