473,385 Members | 1,863 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.

Restart transfertext on error

aas4mis
97
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)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2. Dim strSQL As String
  3.  
  4. On Error GoTo Catch:
  5. Catch:
  6.     If FileExists(strFileToCheck) = True Then
  7.         If varFileDateTime <> FileDateTime(strFileToCheck) Then
  8.             DoCmd.SetWarnings False
  9.             DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False
  10.             DoCmd.OpenQuery "qry_ManifestUpdateAndInsert"
  11.  
  12.             strSQL = "DELETE * FROM tbl_TempManifest"
  13.             DoCmd.RunSQL strSQL
  14.             DoCmd.SetWarnings True
  15.  
  16.             Me.txtUpdated.Value = Now()
  17.             'MsgBox "The file has been modified!"
  18.             varFileDateTime = FileDateTime(strFileToCheck)
  19.         Else
  20.         Me.txtActivity.Value = Now()
  21.         'MsgBox "The file is the same!"
  22.         End If
  23.     End If
  24.  
  25.  
  26. End Sub
Thanks!
Mar 5 '10 #1
5 2881
TheSmileyCoder
2,322 Expert Mod 2GB
I have modified your code to wait 5 seconds before trying again, and trying a maxium of 5 times.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer() 
  2. Dim strSQL As String 
  3.  
  4. On Error GoTo Err_Handler: 
  5. Catch: 
  6.     If FileExists(strFileToCheck) = True Then 
  7.         If varFileDateTime <> FileDateTime(strFileToCheck) Then 
  8.             DoCmd.SetWarnings False 
  9.             DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False 
  10.             DoCmd.OpenQuery "qry_ManifestUpdateAndInsert" 
  11.  
  12.             strSQL = "DELETE * FROM tbl_TempManifest" 
  13.             DoCmd.RunSQL strSQL 
  14.             DoCmd.SetWarnings True 
  15.  
  16.             Me.txtUpdated.Value = Now() 
  17.             'MsgBox "The file has been modified!" 
  18.             varFileDateTime = FileDateTime(strFileToCheck) 
  19.         Else 
  20.         Me.txtActivity.Value = Now() 
  21.         'MsgBox "The file is the same!" 
  22.         End If 
  23.     End If 
  24.  
  25. exit sub
  26. err_Handler:
  27.   dim intErrorCount as intErrorCount
  28.  
  29.   if err.Number=3051 then
  30.     'How many times has this error occured
  31.       intErrorCount=intErrorCount+1
  32.       if intErrorCount=5 then
  33.         msgBox "The maxium amount of attempts was reached. Cannot Import"
  34.         exit Sub
  35.       End If
  36.       Sleep 5000
  37.       Resume 'Maybe you want to do GoTo Catch, im unsure, depends on how the failure effects the rest of the code
  38.  
  39.  
  40.   end if
  41.   msgbox "Error: " & err.Number & ". Description:" & err.Description
  42.  
  43. End Sub
The Sleep is a function of my own, which goes into a module, basicly it will pause for X number of milliseconds.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Declare Function GetTickCount Lib "kernel32" () As Long
  3.  
  4. Public Sub sleep(lngMilliSecs As Long)
  5.     Dim lngTick As Long
  6.     lngTick = GetTickCount
  7.  
  8.     Do While lngTick + lngMilliSecs > GetTickCount
  9.         'Nothing!!
  10.     Loop
  11.  
  12. End Sub
  13.  
Mar 5 '10 #2
aas4mis
97
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.
Mar 5 '10 #3
aas4mis
97
@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).

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Dim strFileToCheck As String
  3. Dim varFileDateTime As Variant
  4.  
  5.  
  6. Private Sub Form_Open(Cancel As Integer)
  7.  
  8.     Application.SetOption "Error Trapping", 1
  9.     strFileToCheck = "c:\inetpub\ftproot\inhouseman.txt"
  10.     varFileDateTime = FileDateTime(strFileToCheck)
  11.  
  12. End Sub
  13.  
  14.  
  15. Private Sub Form_Timer()
  16. Dim strSQL As String
  17.  
  18. On Error GoTo err_Handler:
  19.  
  20.     If FileExists(strFileToCheck) = True Then
  21.         If varFileDateTime <> FileDateTime(strFileToCheck) Then
  22.             DoCmd.SetWarnings False
  23.             DoCmd.TransferText acImportDelim, "InHouseManImportSpecs", "tbl_tempManifest", "c:\inetpub\ftproot\inhouseman.txt", False
  24.             DoCmd.OpenQuery "qry_ManifestUpdateAndInsert"
  25.  
  26.             strSQL = "DELETE * FROM tbl_TempManifest"
  27.             DoCmd.RunSQL strSQL
  28.             DoCmd.SetWarnings True
  29.  
  30.             Me.txtUpdated.Value = Now()
  31.             varFileDateTime = FileDateTime(strFileToCheck)
  32.         Else
  33.             Me.txtActivity.Value = Now()
  34.         End If
  35.     End If
  36.  
  37. Exit Sub
  38. err_Handler:
  39.  
  40.       sleep 1000
  41.       Resume
  42.  
  43. End Sub
  44.  
Thanks for the help TheSmileyOne!
Mar 5 '10 #4
TheSmileyCoder
2,322 Expert Mod 2GB
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.
Mar 5 '10 #5
aas4mis
97
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.
Mar 8 '10 #6

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

Similar topics

1
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...
2
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...
6
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...
11
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...
3
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...
4
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...
3
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...
0
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,...
0
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...
6
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...
0
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,...
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: 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$) { } ...
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...
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...

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.