On Dec 1, 9:04 am, "Stuart McCall" <smcc...@myunrealbox.comwrote:
<Clif...@gmail.comwrote in message
news:e6**********************************@d21g2000 prf.googlegroups.com...
Is there a way in VBA tocheckifalinkedtablein thedatabasehas
beenupdated?
Example:
I have atable"LedgerTemp" which is a direct link to a text file on
the LAN "Ledger.txt"
This text file is periodically updated (overwritten) through out the
day and night by some mainframe jobs.
Right now I just manually run a macro that just basically appends data
from thelinked"LedgerTemp"tableto a localtable"Ledger"
Is there a way I cancheckto seeifmylinkedtablehaschanged and
ifso trigger my macro that appends the new data?
Thanks
Cliff
You can use the FileDateTime function tocheckwhen the file was last
updated. Set up a form, opened hiddenifneed be, and use its timer to poll
the date/time at an interval of your choice (say 300,000 - which is 5
minutes in milliseconds), and trigger your macro in the Form_Timer event.- Hide quoted text -
- Show quoted text -
Thanks all for your help. I made some progress.
I store the result of FileDateTime("LedgerTemp ") into a
local table then I have a form with an "On Load" event, which sets
this value into a field on this form.
The forms timer event is set to 5 minutes (in milliseconds) and in the
"On Timer" event I have this code:
Private Sub Form_Timer()
If FileDateTime("C:\Ledger_dl\Ledger.txt") <Me.LedgerStamp Then
DoCmd.RunMacro ("ImportFile")
End If
End Sub
All the macro does is just basically appends data from the linked
"LedgerTemp" table to a local table "Ledger" then run a couple reports
and also I have it close and open the form so that the new value from
FileDateTime("LedgerTemp ") can be set. The code of the macro is
below....
I have tested this and it seems to be working fine. If I update/change
the file on the LAN the macro runs the and prints the reports but its
kind of freezing it doesn't close and reopen the form so it can set
the new value! The database just freezes with the hourglass on like
something is running in the background??? I have failed to figure out
what going on here and also if the forms timer occurs about the same
time that the file on the LAN updates/changes the macro fails I get an
error message that the query cant run because the file is in use.
Is there a way I can overcome these issues?
Thanks
Cliff
Function ImportFile()
On Error GoTo ImportFile_Err
DoCmd.Echo False, "Importing latest Ledger Data........."
DoCmd.SetWarnings False
' LastLedgerStampQuery1
DoCmd.OpenQuery "LastLedgerStampQuery1", acNormal, acEdit
' LedgerQuery1
DoCmd.OpenQuery "LedgerQuery1", acNormal, acEdit
' LedgerQuery2
DoCmd.OpenQuery "LedgerQuery2", acNormal, acEdit
' C:\Archive\LedgerDB.mdb LedgerDateBatch
DoCmd.TransferDatabase acExport, "Microsoft Access", "C:\Archive
\LedgerDB.mdb", acTable, "LedgerDateBatch", "LedgerDateBatch", False
' LedgerReport
DoCmd.OpenReport "LedgerReport", acNormal, "", ""
' RejectsReport
DoCmd.OpenReport "RejectsReport", acNormal, "", ""
' MAIN MENU
DoCmd.Close acForm, "MAIN MENU"
' MAIN MENU
DoCmd.OpenForm "MAIN MENU", acNormal, "", "", , acNormal
Exit Function
ImportFile_Exit:
Exit Function
ImportFile_Err:
MsgBox Error$
Resume ImportFile_Exit
End Function