473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to trigger an event when a table is opened or a field updated?

beacon
579 512MB
Hi everybody,

[Access 2003]

I created a database about a year ago that stores information about requests that users make to update reports. The fields in the database are updated using a Microsoft Outlook form. Basically, the user opens the Outlook form, fills in the info, sends it to an email group, the data is entered in the database, and the email is received by the members of the email group.

Usually, the Outlook form works just fine, but there have been few occasions when the email will get hung up in the user's Outbox. Strangely enough, the code behind the Outlook form still processes and enters the data into the database, but the email is sent to the members of the email group, which somewhat defeats the purpose of the database since it's used to notify the members of the group that a request has been submitted.

At some point in the future I plan on overhauling this whole process and using something a little more stable, but for the time being I've decided to make due with what I've got by making what I'm hoping are a couple of minor changes.

What I'm trying to do is setup a module or macro that will send an email to the email group whenever the table is opened or when certain fields are opened in that table (there's only one table...it's a simple database).

My problem is that I don't know how to trigger an event that monitors the opening of a table or the changing of data in a specific field on that table. I'm actually not even sure this is possible since the database is likely only open for a very short amount of time between when the email form is sent and the data is processed.

This database really isn't kept open at all and primarily only has action when an email form is sent, so I think (I could be wrong) that would eliminate using a timer to check periodically.

Is this possible and is there some example code I can view to create my module/macro?

Thanks,
beacon
Oct 5 '11 #1
10 10593
Stewart Ross
2,545 Expert Mod 2GB
Hi Beacon. There are no events associated with Access tables at all, so there is no automatic way I can think of by which you could detect a new row insertion or a field update in real time.

An alternative approach which might be worth considering is to generate a change log showing all insertion or modification activity that has taken place (with a timestamp for each change in the log along with the user ID and so on). You could set up your Outlook code to make an entry in the change log each time an insertion or field update takes place.

By monitoring the change log table at intervals through code you could track activity and send out notifications of new entries and changes as necessary.

This is just an idea rather than something fully-formed at present. Change logging is fairly straightforward to implement (although you'd need to double the number of tables you hold in the DB concerned from one to two!).

-Stewart
Oct 5 '11 #2
NeoPa
32,556 Expert Mod 16PB
I'm afraid there are no events triggered in the course of opening table or query objects. Only Form and Report objects have that facility (sets of associated events).

Depending on exactly what happens within your Outlook code (You don't go into much detail there) it may be possible to be a little creative, but fundamentally there is nothing like what you ask for I'm afraid. Fields are never opened as such either, so that part is a no-go too.
Oct 5 '11 #3
beacon
579 512MB
@Stewart - The table I have already is setup basically like a change log. The problem is that I don't check it that often and I was hoping to avoid having to check it...opting instead to make it work for me by emailing me if the data changed. Lazy? Perhaps, but I don't like the idea of checking something daily if there may only be an update once or twice a month. Y'know?

@NeoPa
The code behind the Outlook form basically inputs the values on the form into the associated field using DAO.

Here's a snippet:
Expand|Select|Wrap|Line Numbers
  1. Function Item_Send()
  2.  
  3.     Set Dbe = Application.CreateObject("DAO.DBEngine.36")
  4.     Set MyDB = Dbe.Workspaces(0).OpenDatabase("C:\Tracking.mdb", False, False)
  5.     Set RS = MyDB.OpenRecordSet("tblRequest", DbOpenTable)
  6.  
  7.     'Add a new row to the database and add the data in the 
  8.     'form's fields to the corresponding fields in the database
  9.     '-----------------------------------------------------------
  10.     RS.AddNew
  11.     RS("ReportLocation") = Item.UserProperties("ReportLocation")
  12.     RS("RequestType") = Item.UserProperties("RequestType")
  13.     RS("RequestDate") = Item.UserProperties("RequestDate")
  14.     RS("TimeStamp") = Item.UserProperties("TimeStamp")
  15.     RS("RequestorFName") = Item.UserProperties("FirstName")
  16.     RS("RequestorLName") = Item.UserProperties("LastName")
  17.     RS("RequestorPhone") = Item.UserProperties("PhoneNumber")
  18.     RS("RequestReason") = Item.UserProperties("RequestReason")
  19.  
  20.     'Grab the unique ID from the database and 
  21.     'assign it to the AutoID field on the form
  22.     '-------------------------------------------
  23.     Item.UserProperties("AutoID").Value = RS("RequestID")
  24.  
  25.     'Update the database, move the cursor to the 
  26.     'last row in the database, and close the database
  27.     '--------------------------------------------------
  28.     RS.Update
  29.     RS.MoveLast
  30.     RS.Close
  31.     MyDB.Close
  32.  
This is probably not possible, but if I add a module with a subroutine that has code to email, can I call that subroutine from DAO?
Oct 5 '11 #4
Stewart Ross
2,545 Expert Mod 2GB
As NeoPa and I have both mentioned, there are no events associated with tables. As there are no event listeners or handlers available, it is simply not possible for DAO to call a bespoke subroutine at all.

-Stewart
Oct 5 '11 #5
NeoPa
32,556 Expert Mod 16PB
If the only time data is added to the table is within your own Outlook code then it should be easy enough to change the code such that, when any update occurs, it also notifies you that it has.

I think that's your best route to be fair.

PS. Don't worry. I think we are all lazy people looking to save time and energy by avoiding laborious tasks. That's my main reason for loving programming and logic. That and the fact that so many people simply can't do what I find relatively easy (Maybe that's a little conceit showing, I don't know).
Oct 5 '11 #6
Rabbit
12,516 Expert Mod 8TB
So... I may be wrong here but it sounds like you're trying to fight fire with fire.

You have code that inserts data into a database and sends an e-mail to let people know something was inserted. The problem is that, from time to time, the e-mail goes into limbo and doesn't send. So what you want to do is send another e-mail, but based off a different trigger? Won't that run the risk of getting stuck in limbo as well?
Oct 5 '11 #7
beacon
579 512MB
@Stewart - Thanks...I just wanted to make sure I had turned over every rock.

@NeoPa & @Rabbit - The problem is that, based on our email setup, which I have no control over, the Outlook forms are somewhat finicky...despite best efforts, they are easy to one-off. So, instead of trying to get the Outlook form to send the notification like it's supposed to, but failing at occasionally, I was trying to see if there was a way to prompt the database to interface back with Outlook, outside of the Outlook form (using Redemption), to send a secondary email that I thought would be more stable than the other.

Maybe I can take Stewart's earlier response and tweak it so that it shows the last entry made on a given day, then write a script in VBScript and schedule it to open the database (that now has an AutoExec macro), check to see if the last entry in the main table matches the entry in the log, and if it's different, wait long enough for the module to run before closing the database. The log would then swap the last entry in the main table with the entry in the log (to keep it small...no reason to duplicate all the data) and the schedule would launch again the same time the next day.

Hopefully I could get it to run in the background once or twice a day without it interrupting other things I might be working on. Does that sound like a possible solution?

Thanks,
beacon
Oct 6 '11 #8
Rabbit
12,516 Expert Mod 8TB
That's what I was going to suggest, however, instead of logging the last record sent, I would suggest an extra column.

[Sent] Boolean Default: False

Then you can use a query to send all the false records and run an update query to set them to true.

I'm looking into an alternative, I'll post back and let you know how it turns out.
Oct 6 '11 #9
NeoPa
32,556 Expert Mod 16PB
You may find that Invoking a Database From the Command Line helps you to get something like that working. It may even give you some ideas as to what you might be able to achieve relatively straightforwardly.

I didn't realise this was what you were after earlier, otherwise I would have suggested it then.
Oct 6 '11 #10
Rabbit
12,516 Expert Mod 8TB
I was trying to see if you can access a VBA function from an ADODB connection, which is what I assume you're using to run your update query. But it turns out you can't so that's a bust.

However, if it's just the e-mail code that's hanging, you could instantiate an Access object and run the VBA function in Access to send an e-mail.
Oct 6 '11 #11

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

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
3
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the...
3
by: Dustin Davis | last post by:
Is it possible to trigger an event in VB.NET whenever anything is copied to the clipboard?
1
by: tom c | last post by:
In ASP.net is there any way to trigger an event when you change the selected value of a drop down list box?
2
by: Tom_F | last post by:
To comp.databases.ms-access -- I would like to trigger an event when I close a form -- but ONLY when the data in the "RecordSource" table has been updated. I tried using the AfterUpdate event,...
2
by: kilik3000 | last post by:
Is there a way to catch an event/trigger that *might* be fired when a usb thumb drive is inserted into a Vista PC? The reason I ask is that I'd like to catch that event and back up the content...
2
by: sandpking | last post by:
I have the query below (as a row source)update a list box with all the employees of a supervisor. The problem is it doesn't automatically update when a the referened field on the form (supervisor)...
1
by: garymarshallsa | last post by:
I am new to SQL and have a MSSQL 2000 database data_02 that consists of two tables Table1 oeordhdr_sql fields ORDDATE Table2 oeordlin_sql fields REQDATE, SHPDATE I am needing a...
5
by: laredotornado | last post by:
Hi, Is there a way to trigger an event when the value of a hidden field changes? At a certain point in time my hidden field is getting changed to a value that I don't want but I can't find a...
1
Ciary
by: Ciary | last post by:
hi all, i wasnt really sure where to post this since it's a combination of Javascript and PHP. i'm trying to make a fileuploader without reloading the page. my structure: at the moment, i can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...

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.