473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New Record to Automatically Run a Macro

1 New Member
I have created a macro in Access 2003 that will send a report of the last full record added to a table via e-mail. The table is actually being populated from an InfoPath form. What I would like to do is to have my macro run automatically when ever a new record is added to the table. Can anyone tell me how to do that?
Jul 24 '07 #1
1 3450
JConsulting
603 Recognized Expert Contributor
I have created a macro in Access 2003 that will send a report of the last full record added to a table via e-mail. The table is actually being populated from an InfoPath form. What I would like to do is to have my macro run automatically when ever a new record is added to the table. Can anyone tell me how to do that?

Since tables don't have "events" that might pop some code or your macro to run when a record is added...there ARE a couple of options. But keep in mind Access is event driven. That means a click, doubleclick, mousedown, etc...triggers things to happen.

One other option that doesn't necessarily require one of the above is a simple solution.

If you create a small form you can set up an On_Timer event that can check the Count of records in your table every few minutes or so. If the number is greater than the last time you checked, then you can trigger your macro.

A form like this can be set to invisible ("acHidden") so that it's not intrusive to the rest of your application.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Option Compare Database
  4.  
  5. Dim oldcount As Long
  6. Dim newcount As Long
  7.  
  8. Private Sub Form_Open(Cancel As Integer)
  9. oldcount = DCount("*", "one")
  10. End Sub
  11.  
  12. Private Sub Form_Timer()
  13. newcount = DCount("*", "one")
  14. If newcount > oldcount Then
  15.      DoCmd.RunMacro "yourmacro"
  16. End If
  17. oldcount = newcount
  18. End Sub
  19.  
  20.  
Jul 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2213
by: Jason A. Thompson | last post by:
Dear Access Gurus, I have a database which I hoped to use to administer questionnaires, or rather that someone who knows nothing about Access could use to administer them. Each q'aire item is on...
7
2250
by: Megan | last post by:
Hi everybody- I inherited a database that somehow uses a bound combo box as a record selector. Let me give you some background. The form is based on data from 2 tables. The first table, Person,...
3
6202
by: Randy | last post by:
I have been able to set up a Find Record Button on my switchboard to take me to a form with the correct case number by using a parameter query and macro. When I try to run the Find Record button...
27
3912
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!=...
5
3473
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
4
2903
by: BerkshireGuy | last post by:
Is there a way to create a shortcut to open a MS Acccess DB and have it go to a specific record? In my DB, when a user delegates a record to another users, I currently send out an email to the...
2
4724
by: mscurto | last post by:
Is there a way to set up access to open and run a query in a particular database at a particular time each day? This would be run from a Windows 2000 desktop.
1
2182
by: Matt | last post by:
I have table that has the following fields: JobNumber WeekEndingDate ReportRequired_01 ReportRequired_02 every Friday morning the weekending date changes. I need to automatically generate...
5
2719
brightshadow
by: brightshadow | last post by:
I have a super simple Access DB with four tables and one form.. I'm an old hand at Excel VBA but am just starting with Access, so this is likely a totally stupid question, but here goes anyway. In...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.