473,385 Members | 1,372 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,385 software developers and data experts.

Check if a linked table in the database has been updated/changed

Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"

Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?

Thanks
Cliff
Dec 1 '07 #1
10 4792

<Cl*****@gmail.comschreef in bericht news:e6**********************************@d21g2000 prf.googlegroups.com...
Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"

Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?

Thanks
Cliff
If 'changed' means 'new records added' ... then you could try something like

VBA:
If DCount("*","LedgerTemp") DCount("*","Ledger") then RunYourMacro

Macro
Or call your macro at startup and put this in the condition of your macro
DCount("*";"LedgerTemp") DCount("*";"Ledger")

Arno R
Dec 1 '07 #2
<Cl*****@gmail.comwrote in message
news:e6**********************************@d21g2000 prf.googlegroups.com...
Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"

Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?

Thanks
Cliff
You can use the FileDateTime function to check when the file was last
updated. Set up a form, opened hidden if need 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.
Dec 1 '07 #3
"Stuart McCall" <sm*****@myunrealbox.comwrote in message
news:fi*******************@news.demon.co.uk...
<Cl*****@gmail.comwrote in message
news:e6**********************************@d21g2000 prf.googlegroups.com...
>Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"

Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?

Thanks
Cliff

You can use the FileDateTime function to check when the file was last
updated. Set up a form, opened hidden if need 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.
Addendum: I should have finished that with:

and trigger your macro in the Form_Timer event if the date/time has changed.
Dec 1 '07 #4
On Dec 1, 11:33 am, Clif...@gmail.com wrote:
Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"

Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?

Thanks

Cliff
If you just want to check to se if the text file has changed you
checkand set the archive attribute of the file:

Public Sub RemoveArchiveAttribute(ByVal FullPath$)
SetAttr FullPath, Not vbArchive And GetAttr(FullPath)
End Sub

Public Function HasChanged(ByVal FullPath$) As Boolean
HasChanged = GetAttr(FullPath) And vbArchive
End Function

You could remove the attribute when you import.
It will be set (back on) when/if the file is changed.
You could check to see if it is set.
If so then import and remove again.

Of course, the Windows NTBackup (and other) utility removes the
attribute, but unless you are backing up frequently this is unlikely
to be a big problem.

Dec 1 '07 #5
On Dec 1, 8:50 am, "Arno R" <arracomn_o_s_p_...@planet.nlwrote:
<Clif...@gmail.comschreef in berichtnews:e6**********************************@d 21g2000prf.googlegroups.com...
Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"
Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?
Thanks
Cliff

If 'changed' means 'new records added' ... then you could try something like

VBA:
If DCount("*","LedgerTemp") DCount("*","Ledger") then RunYourMacro

Macro
Or call your macro at startup and put this in the condition of your macro
DCount("*";"LedgerTemp") DCount("*";"Ledger")

Arno R
Thanks for your help
Dec 2 '07 #6
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 to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"
Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?
Thanks
Cliff

You can use the FileDateTime function to check when the file was last
updated. Set up a form, opened hidden if need 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.
Thanks for your help
Dec 2 '07 #7
On Dec 1, 9:45 am, lyle <lyle.fairfi...@gmail.comwrote:
On Dec 1, 11:33 am, Clif...@gmail.com wrote:
Is there a way in VBA to check if a linked table in the database has
been updated?
Example:
I have a table "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 the linked "LedgerTemp" table to a local table "Ledger"
Is there a way I can check to see if my linked table has changed and
if so trigger my macro that appends the new data?
Thanks
Cliff

If you just want to check to se if the text file has changed you
checkand set the archive attribute of the file:

Public Sub RemoveArchiveAttribute(ByVal FullPath$)
SetAttr FullPath, Not vbArchive And GetAttr(FullPath)
End Sub

Public Function HasChanged(ByVal FullPath$) As Boolean
HasChanged = GetAttr(FullPath) And vbArchive
End Function

You could remove the attribute when you import.
It will be set (back on) when/if the file is changed.
You could check to see if it is set.
If so then import and remove again.

Of course, the Windows NTBackup (and other) utility removes the
attribute, but unless you are backing up frequently this is unlikely
to be a big problem.
Thanks for your help
Dec 2 '07 #8
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

Dec 7 '07 #9
"CliffKing" <Cl*****@gmail.comwrote in message
news:66**********************************@d61g2000 hsa.googlegroups.com...
On Dec 1, 9:04 am, "Stuart McCall" <smcc...@myunrealbox.comwrote:
><Clif...@gmail.comwrote in message

news:e6**********************************@d21g200 0prf.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
That's quite a batch of work going on there. I think what you need to do to
solve the 'freezing' problem is to switch off the timer while the ImportFile
procedure runs:

Function ImportFile()
On Error GoTo ImportFile_Err
Me.TimerInterval = 0

....

Me.TimerInterval = 300000
DoCmd.OpenForm "MAIN MENU", acNormal, "", "", , acNormal
Exit Function
(that's assuming the code exists in your form's module. If it doesn't,
you'll need to replace Me with Forms!MyFormName)

Let's see if that cracks your 1st problem, then move on to the file locking
problem.

Dec 7 '07 #10
DoCmd.Echo False, "Importing latest Ledger Data........."
DoCmd.SetWarnings False
I just spotted these lines in your function. The first line is probably what
is making your app 'freeze'. You need to switch Echo and SetWarnings on
again before your function exits:

ImportFile_Exit:
DoCmd.Echo True
DoCmd.SetWarnings True
Exit Function
Dec 7 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
6
by: Max | last post by:
Hi, I have SqlServer 2000 as back end and Access 2000 as front-end. All tables from Sqlserver are linked to Access 2000. I am having write conflict problem with one of my form which is bound to...
3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
5
by: dadofgage | last post by:
I have an application that was written in access and it is linked to data on a microsoft SQL server. I have no problems getting the data out of the database but if I want to update the data, I...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
4
by: Wayne Wengert | last post by:
I am trying to create a VB.NET Windows application to move some data from a local Access DB table to a table in a SQL Server. The approach I am trying is to open an OLEDB connection to the local...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
1
Stang02GT
by: Stang02GT | last post by:
Hello, In the final stages of this Access project(That i've been badgering people with questions about) the last modification that is to be made is another one that i have no idea if its possible...
2
by: Ben | last post by:
Hi! All of a sudden on a newer version of our application a check box on the "Produce Invoice" form cannot be checked. I did not do any changes to this form at all. Below are the things that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.