I have a loop that constantly checks a text file for modifications. On mod the data will be imported to a table via docmd.transfertext. The problem is if another user (ftpuser) is uploading at the same time I get a 3051 error.
Is there a way to fail on error with no warning and restart the loop? This would be much easier if there was a way to get a return value out of docmd.transfertext.
Here's my failed attempt. (FileExists() available at http://allenbrowne.com/func-11.html) -
Private Sub Form_Timer()
-
Dim strSQL As String
-
-
On Error GoTo Catch:
-
Catch:
-
If FileExists(strFileToCheck) = True Then
-
If varFileDateTime <> FileDateTime(strFileToCheck) Then
-
DoCmd.SetWarnings False
-
DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False
-
DoCmd.OpenQuery "qry_ManifestUpdateAndInsert"
-
-
strSQL = "DELETE * FROM tbl_TempManifest"
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
-
Me.txtUpdated.Value = Now()
-
'MsgBox "The file has been modified!"
-
varFileDateTime = FileDateTime(strFileToCheck)
-
Else
-
Me.txtActivity.Value = Now()
-
'MsgBox "The file is the same!"
-
End If
-
End If
-
-
-
End Sub
Thanks!
5 2881
I have modified your code to wait 5 seconds before trying again, and trying a maxium of 5 times. - Private Sub Form_Timer()
-
Dim strSQL As String
-
-
On Error GoTo Err_Handler:
-
Catch:
-
If FileExists(strFileToCheck) = True Then
-
If varFileDateTime <> FileDateTime(strFileToCheck) Then
-
DoCmd.SetWarnings False
-
DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False
-
DoCmd.OpenQuery "qry_ManifestUpdateAndInsert"
-
-
strSQL = "DELETE * FROM tbl_TempManifest"
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
-
Me.txtUpdated.Value = Now()
-
'MsgBox "The file has been modified!"
-
varFileDateTime = FileDateTime(strFileToCheck)
-
Else
-
Me.txtActivity.Value = Now()
-
'MsgBox "The file is the same!"
-
End If
-
End If
-
-
exit sub
-
err_Handler:
-
dim intErrorCount as intErrorCount
-
-
if err.Number=3051 then
-
'How many times has this error occured
-
intErrorCount=intErrorCount+1
-
if intErrorCount=5 then
-
msgBox "The maxium amount of attempts was reached. Cannot Import"
-
exit Sub
-
End If
-
Sleep 5000
-
Resume 'Maybe you want to do GoTo Catch, im unsure, depends on how the failure effects the rest of the code
-
-
-
end if
-
msgbox "Error: " & err.Number & ". Description:" & err.Description
-
-
End Sub
The Sleep is a function of my own, which goes into a module, basicly it will pause for X number of milliseconds. - Option Compare Database
-
Private Declare Function GetTickCount Lib "kernel32" () As Long
-
-
Public Sub sleep(lngMilliSecs As Long)
-
Dim lngTick As Long
-
lngTick = GetTickCount
-
-
Do While lngTick + lngMilliSecs > GetTickCount
-
'Nothing!!
-
Loop
-
-
End Sub
-
I still get the 'Run-time error '3051':' popup which stops the program. I won't be monitoring this so I don't want that popup to show.. Any way to disable the popup?
When entering debug mode, the cursor is on the docmd.transfertext line.
@aas4mis
My bad, I've been looking at the same code for too long. There was a msgbox in the error handler. I've modified to just sleep 1 second and retry, no messages. This seems to have done the trick. Here's the full code for the form (minus the modules noted in earlier posts). - Option Compare Database
-
Dim strFileToCheck As String
-
Dim varFileDateTime As Variant
-
-
-
Private Sub Form_Open(Cancel As Integer)
-
-
Application.SetOption "Error Trapping", 1
-
strFileToCheck = "c:\inetpub\ftproot\inhouseman.txt"
-
varFileDateTime = FileDateTime(strFileToCheck)
-
-
End Sub
-
-
-
Private Sub Form_Timer()
-
Dim strSQL As String
-
-
On Error GoTo err_Handler:
-
-
If FileExists(strFileToCheck) = True Then
-
If varFileDateTime <> FileDateTime(strFileToCheck) Then
-
DoCmd.SetWarnings False
-
DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False
-
DoCmd.OpenQuery "qry_ManifestUpdateAndInsert"
-
-
strSQL = "DELETE * FROM tbl_TempManifest"
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
-
Me.txtUpdated.Value = Now()
-
varFileDateTime = FileDateTime(strFileToCheck)
-
Else
-
Me.txtActivity.Value = Now()
-
End If
-
End If
-
-
Exit Sub
-
err_Handler:
-
-
sleep 1000
-
Resume
-
-
End Sub
-
Thanks for the help TheSmileyOne!
If the error number is 3051, the error message should never be shown with the code I provided.
The msgbox and counter was there to allow a maxium amount of attempts before "timing out" or whatever, so you dont go into a infinite loop (which you could probably Break your way out of but still.
If your code works for you, thats good! I just dont really see how the msgbox's would fire unless it fails 5 times in a row, or the err.number is not 3051.
I probably stress tested it a little too much and reached the 5 count limit. But that's ok for my purposes, this will not be monitored so I don't need notifications. I didn't do a debug.print on the intErrorCount so I couldn't tell you if the limit was reached or not, but your code worked as planned, just not my plan. :)
side note:
for you copy and pasters out there (nothing wrong with that), the "dim intErrorCount as intErrorCount" in earlier posts should be dim'd as integer.
Thanks again TheSmileyOne, much time saved.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sue |
last post by:
Using WindowsXP and AccessXP in 2000 Mode
When I run the following code, I get error 3027
"Cannot Update. Database or object is read only."
StrFolder = "C:\Comic Box\WebStore Interface...
|
by: BigData |
last post by:
I am attempting to create a delimited text file by using
DoCmd.Transfertext as shown here.
DoCmd.TransferText acExportDelim, "ExportSpec", "QryFinalExport",
"Fileout.txt"
This works fine as...
|
by: Vladislav Moltchanov |
last post by:
I have discovered a couple of years ago, that import with
DoCMD.TransferText for CSV text file doesn’t work in Acc2000, while it
works perfectly in ACC97.
which has been discussed on this...
|
by: Shyguy |
last post by:
I need to import a text file pretty much daily. I download the file
and change the name to a standard name and then run the code to import
the file into a table in my database. The problem is...
|
by: Typehigh |
last post by:
I am a pretty saavy user, but I am having a real problem with the
DoCmd.TransferText operation.
I manually used the File>Get External Data> Import routine to set up an
import specification. It...
|
by: axelleforever |
last post by:
Bonjour,
La première colonne de mon fichier texte (séparateur points-virgules)
contient des valeurs alphanumériques (1,2a,3u etc). Je constate que
seules les valeurs numériques sont importées...
|
by: holdemfoldem |
last post by:
Hi. I'm new to this board and have a few questions about using the
method referred to in the topic of this message.
I have manually transferred over 1/2 million records from a text file
into my...
|
by: Richard Beacroft |
last post by:
Trying to write a C# Windows App to export all objects and content from
2 MSAccess 97 databases for comparison analysis.
very little documentation found.
Have managed to instantiate MSAccess,...
|
by: matchine |
last post by:
This is a recommendation based on my research on an issue with the
transfer text functionality. The comments below were from a tech I
approched for help.
"The transfer text process blocked...
|
by: Tim Marshall |
last post by:
IN trying to export a Jet query (an actual saved Jet querydef which is
written against a pass through query - not that that should be a
problem) to text via either the File->Export... menu item or...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
|
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...
| |