Hi all,
I managed to write a code that will go through a table and remove any faulty data from it.
My system generates out a monthly text file containing all the events that have happened over the month. Each event is detailed within 6 lines of text, any more or any less is considered faulty. The start of each event is determined by "0~0~ES~1~".
Here's the weird part, I tested my program with a test file which consists of about a thousand lines of text, and it runs perfectly. However, when I used it on the actual file which consists of about half a million lines of text, it's always giving me back different data.
E.g. my first test on the actual file generated 92123 records, whereas my second test generated 91800.
I did not change my codes at all, so could this be a bug?
I really have no idea how to rectify this as I see nothing wrong with my codes or data. - Sub Del_Invalid(strSearch As String)
-
-
Dim db As Database, rst As Recordset, lngcnt As Long, k As Long
-
-
On Error GoTo Del_Invalid_Err
-
-
Set db = CurrentDb
-
Set rst = db.OpenRecordset("Oct", dbOpenTable)
-
-
lngcnt = 0
-
With rst
-
-
Do While Not .EOF
-
Debug.Print !Field1
-
-
If InStr(1, !Field1, "0~0~ES~1~") > 0 Then
-
If lngcnt > 6 Then
-
'Delete offending records
-
.MovePrevious
-
For k = 1 To lngcnt
-
.Delete
-
.MovePrevious
-
Next
-
lngcnt = 0
-
Else
-
lngcnt = 1
-
End If
-
Else
-
lngcnt = lngcnt + 1
-
End If
-
.MoveNext
-
Loop
-
' In case last one was offending
-
If lngcnt > 6 Then
-
'Delete offending records
-
.MovePrevious
-
For k = 1 To lngcnt
-
.Delete
-
.MovePrevious
-
Next
-
End If
-
-
End With
-
-
Del_Invalid_Exit:
-
On Error Resume Next
-
rst.Close
-
Set rst = Nothing
-
Set db = Nothing
-
Exit Sub
-
-
Del_Invalid_Err:
-
MsgBox "Error " & Str$(Err.Number) & " = " & Err.Description
-
Resume Del_Invalid_Exit
-
-
End Sub
- Private Sub Command0_Click()
-
Call Del_Invalid("0~0~ES~1~")
-
End Sub
7 1139 jforbes 1,107
Recognized Expert Top Contributor
I doubt you are running into a bug. I assume you have exclusive access to the table that you are modifying, if not maybe there is a record lock issue.
One thing that concerns me is the .MovePrevious method. Moving through a Recordset and deleting records is tricky enough without moving in both directions. You could be running into a timing issue with your reads and writes. Given this, you might want to try to lockdown your Recordset when opening it. I haven't tested this out, but you might want to do something like: - Set rst = db.OpenRecordset("Oct", dbOpenTable,dbDenyRead,dbPessimistic)
A way you might be able to sidestep this is to create a query to perform your deletes and execute it. What you are doing is complex, but it doesn't seem too complex for a query.
Hi jforbes,
I just did a thorough check. My codes are working fine, but I'll try your suggestion to be safe :)
Anyway, I think the problem lies with Access's import function. I imported my data using the external data tab and with the same settings, but when I search for, example record number "523111", both tables will show a different value in the field. I feel that my 500000+ line text file may be too much for access to handle properly. So I'm gonna try splitting it and importing again.
Rabbit 12,516
Recognized Expert Moderator MVP
When you import data, there's no way to guarantee the order in the tables unless you write a script to import it line by line.
Hi rabbit,
Would you by any chance know how to or can provide me an example of the code to import line by line?
Rabbit 12,516
Recognized Expert Moderator MVP
An example wouldn't be much help because the bulk of it would change depending on the file layout. But the basic steps are:
1) Read a file line by line
2) Break out the line into the fields you need (this is where the bulk of the code would be and also where the changes are depending on the layout)
3) Insert that row of data into the database table with an autonumber field.
Steps 1 and 3 are fairly standard. Number 2 is where there are lots of changes depending on your file layout.
Hey rabbit,
I've been reading on this recordset method in http://bytes.com/topic/access/answer...into-ms-access
However, I'm still unable to figure out how to modify the code to work with my data due to my poor VBA knowledge. I'm really bad with this "Mid$" stuff.
Basically, I just want each line in my text file to occupy one field in my table first. I want the entire line (each line has a different number of characters) to be placed into the field, so I don't think I really need to do the Mid$ thingy right?
E.g.
Line 1 is placed in Row 1 Column 1
Line 2 is placed in Row 2 Column 1
Line 3 is placed in Row 3 Column 1
.
.
.
Line X is placed in Row X Column 1
Rabbit 12,516
Recognized Expert Moderator MVP
Yes, you're right. If you only have one field, then you don't need to mess with the Mid stuff.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nasser |
last post by:
Hello,
I am coding a mathematical model with VC++. When I debug the code, I
face with no erroe, but during executing, I face with below error
"Unhandled exception at 0x0040c275 in Tar.exe:...
|
by: Bruce Pataki |
last post by:
I am creating an MFC application with activeX document server support. The
application runs perfectly fine when i run as a standalone application. But
when i run the application in Internet...
|
by: Jim |
last post by:
Lately, I've been seeing a lot of those dynamically created access code images
on web forms. You know, some little jpg or gif image that has a random series of
letters and numbers. The form says...
|
by: bhreddy |
last post by:
Hi All,
Can someone help me out how can I resolve the error "0xC0000005: Access
violation reading location 0x513112f4"?
Steps I followed...
1. I ran the application at DOS prompt
2. After...
|
by: Yanping Zhang |
last post by:
Hi All,
I need to use this C routine in python and there is a void pointer parameter in it:
(this routine was written by someone else):
myfunc(int a, (void *)userdata, bool b)
I saw someone...
|
by: Jim Langston |
last post by:
Microsoft Visual C++ .net 2003. I was just curious what numeric_limits for
std::string would give me so wrote this:
#include <iostream>
#include <string>
#include <limits>
int main()
{...
|
by: raghunadhs |
last post by:
Hi all,
i have developed a ".dll" in vc++, regarding to find out CRC32. and in my V.B 6.0 application i am calling that .dll.
If i run my v.b application it is working means.. i am able to find...
|
by: ycinar |
last post by:
A quick question:
Why doesn't the following code catch the Access violation reading location exception?
it crashes on line if ( xyz ) with an Access violation reading location exception. Is not...
|
by: Pinux |
last post by:
Hi,
I am writing a multi-threads encryption application. The idea of the code is to create a number of threads to encrypt files. I have a thread pool say the maximum threads is 10. If the number...
|
by: alexandertfg |
last post by:
I finished working on my first draft for my email homework for my C++ class but when debugging I recieved a Access violation reading location 0x00370000 error. I know that it has to do with a stack...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |