Link to home
Start Free TrialLog in
Avatar of Eric - Netminder
Eric - NetminderFlag for United States of America

asked on

Script to poll database 3/3

This is part 3 of a 3-part question; the others are located at
https://www.experts-exchange.com/questions/28360144/Update-previous-record-1-3.html
https://www.experts-exchange.com/questions/28360145/Update-lots-of-previous-records-2-3.html

In the attached database, which is data retrieved from an ODBC-connected database to which I have read-only access, I can import the data shown in tblOrig. There are hundreds of IDNumbers; this is filtered data for one of them. Essentially, the table from which I am drawing this information lists every IDNumber, and revisions to it are shown in the Revision field, so the unique identifier of each record in the table is IDNumber & Revision.

I don't have to look at this data every single day, but what I would like to do is build something that goes and looks at the ODBC database and pulls the revisions done since the last time I added them. If it's Thursday, that probably means yesterday, but if it's Tuesday, it might have been yesterday, but it could have also been last Friday. I only need the new ones added to my current table.

Part 1 of this question has to do with automatically updating records that I import from the ODBC database. Part 2 of this quesiton has to do with updating thousands of existing records.

My Access coding skills are... rusty... so any assistance would be greatly appreciated.

Thanks,

ep
efptest01.mdb
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

You might not need this at all.
See my suggestion in 2/3.

/gustav
Avatar of Eric - Netminder

ASKER

Gustav,

I don't think I was clear.

I pull the data into my Access database through ODBC (essentially, I've built a front end for it), but I can't edit the data in the original database.

The EditDate field is in the ODBC database. What I do now is pull all the data down and manipulate it for my purposes (functionality that doesn't exist in the ODBC database). What I want to do is pull down ONLY those new records (revisions) since the last time I pulled the data down.

If that's not possible, I can always do a CreateTable query that pulls all the data every time I need it, but that seems like overkill.

Does that make sense?

ep
Is the edit date always going to be greater than the prior time you imported the data? As in the creators/editors of the data don't go back and edit the prior stuff? Or put in yesterdays date?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jim,

Good question; I've asked, but haven't heard back. For the time being, let's assume that since it's a proprietary system and that it's locked down from people tinkering with the data that the Start (nee Edit) Date is the actual date of the revision.

Gustav,

So you're suggesting simply introducing a variable into the query that pulls the data down, and not bothering with automating it? That's certainly doable.

ep
If you had to compare for revised dates then you get into a RBAR (Row-By-Agonizing Row)  situation.

But it becomes simple if the last start date in the tblOrig is the qualifier for looking for new stuff.
The query
INSERT INTO tblOrig (IDNumber, Revision, LocationString, EditDate)
SELECT IDNumber, Revision, LocationString, EditDate
FROM odbcTbl
WHERE odbcTbl.EditDate > (SELECT Max(tblOrig.EditDate) FROM tblOrig);

Open in new window


The only risk in this is if you run it in the middle of the day and stuff is added later the same day you may miss it.  One that I do is have function tied to an "autoexec" from that opens on DB startup. If the time is between say 7A and 8A the form runs the functions/queries assigned in the VBA code. If it is outside that time then the form just shuts down and no one notices it. Then I have a scheduled task to open the DB at 7:30 A every day and it runs the stuff for me.
> So you're suggesting simply introducing a variable into the query that
> pulls the data down, and not bothering with automating it?

Yes.

/gustav
Finally got a response; the revisions (and the revision date) are posted immediately, so when the ODBC database gets polled, any activity is logged.

So it's just a matter of creating a query that searches the data for any records created after the last time. That should be easy enough.

Thanks for your help!

ep
You are welcome!

/gustav