473,657 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code to fix corrupt table

I have come across some code to walk through the records of a corrupt table
and copy it record by record to a new table. It comes from the MVPS.Org
site and is as follows.
-----------------------
(Q) How can I recover records from a corrupt table?

(A) First, using Access while in the database window, copy the table's
structure only from the corrupt table, if possible. Then using the code
below, copy each individual row from the old table to the new one until it
encounters an error. The error routine displays the error, skips one row,
moves to the next and Resumes at Addit where it continues to move data from
the old table to the new table one row at a time.
' ********* Code Start ***********
' This code was originally written by Norm Chezem

' It is not to be altered or distributed,

' except as part of an application.

' You are free to use it in any application,

' provided the copyright notice is left unchanged.

'

' Code Courtesy of

' Norm Chezem

'

Function CopyRes()

Dim db As Database

Dim OldRes As Recordset

Dim NewRes As Recordset

Dim ErrMsg1 As String

Dim RecCount As Long

On Error GoTo err_Proc

Set db = CurrentDb()

Set OldRes = db.OpenRecordse t("tbl_Reservat ions")

Set NewRes = db.OpenRecordse t("tbl_New_Res" )

RecCount = 0

OldRes.MoveFirs t

Do While Not OldRes.EOF

Addit:

NewRes.AddNew

NewRes![ResID] = OldRes![ResID]

'CONTINUE COPYING ALL ROWS FROM OLD TBL TO NEW

NewRes.Update

RecCount = RecCount + 1

DoEvents

If RecCount Mod 10000 = 0 then

MsgBox RecCount 'Show progress every 10,000 rows

End If

Loop

MsgBox RecCount 'Show total successful record count

OldRes.Close

NewRes.Close

db.close

Proc_Exit:

Exit Function

Err_Proc:

MsgBox "<Error>" & Error$

OldRes.MoveNext 'Skip this corrupt row

Resume Addit 'Continue at Addit

End Function

' ********* Code End ***********

I have worked out that the NewRes![ResID]=OldRes![ResID] probably has to be
customised to reflect my unique record name.

What happens when I run this is I get an error for each row that occurs
whenever I have a [Required] field and it tells me that it can't be null as
it is a requred field.

I have the procedure in a module and I am simply typing CopyRes in the
Immediate window. I have changed the table names in it to suit my
situation. Can anyone see what I am doing wrong?

dixie


Nov 13 '05 #1
4 1928
huh? This code is missing a serious chunk! Okay, assuming that the
code is copying field by field into the new table, you need to do
something like

'--add a new blank record to the destination table
rsDest.AddNew

'---populate all the fields in the new record from values from the
current record in the source table
for intCounter = 0 to rsSrc.Fields.Co unt-1
rsDest.Fields(i ntCounter) = rsSrc.Fields(in tCounter)
next intCounter
'---save the values in the new record
rsDest.Update

Okay, so then you have to call that for each record in the source
table, so you wrap it in a Do Until rsSrc.EOF thing and away you go.

Nov 13 '05 #2
The code is supposed to be complete and is at
http://www.mvps.org/access/tables/tbl0018.htm - I just altered the names of
the tables involved and then the line:
NewRes![ResID] = OldRes![ResID] which I took to be the uniqe ID number for
the table.dixie<pi* *******@hotmail .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
huh? This code is missing a serious chunk! Okay, assuming that the
code is copying field by field into the new table, you need to do
something like

'--add a new blank record to the destination table
rsDest.AddNew

'---populate all the fields in the new record from values from the
current record in the source table
for intCounter = 0 to rsSrc.Fields.Co unt-1
rsDest.Fields(i ntCounter) = rsSrc.Fields(in tCounter)
next intCounter
'---save the values in the new record
rsDest.Update

Okay, so then you have to call that for each record in the source
table, so you wrap it in a Do Until rsSrc.EOF thing and away you go.

Nov 13 '05 #3
Sorry about the formatting of that last message. It just occurred to me
Pieter after I reread your message that the single line:
NewRes![ResID]=OldRes![ResID] is just an example of doing one of the fields
of the table. So, I do have to include all the fields as lines at that
stage of the code. There are a lot of fields in this table. I like your
code that seems just to automatically add each field. I presume I need to
dim intcounter as something before I can use that code - dim intCounter as
integer?

I'll have a play with it with a smaller table.

Thanks

dixie

<pi********@hot mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
huh? This code is missing a serious chunk! Okay, assuming that the
code is copying field by field into the new table, you need to do
something like

'--add a new blank record to the destination table
rsDest.AddNew

'---populate all the fields in the new record from values from the
current record in the source table
for intCounter = 0 to rsSrc.Fields.Co unt-1
rsDest.Fields(i ntCounter) = rsSrc.Fields(in tCounter)
next intCounter
'---save the values in the new record
rsDest.Update

Okay, so then you have to call that for each record in the source
table, so you wrap it in a Do Until rsSrc.EOF thing and away you go.

Nov 13 '05 #4
Well, I must admit I've given up on making this work easily. I had a
corrupted table last week with over 15,000 records which I had to search
through for 2 corrupted records, then copy block by block the good messages
as I couldn't delete the corrupted ones. This is just so slow. If I could
have had this working, I am sure I could have pressed a button and made a
nice cup of tea.

dixie

<pi********@hot mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
huh? This code is missing a serious chunk! Okay, assuming that the
code is copying field by field into the new table, you need to do
something like

'--add a new blank record to the destination table
rsDest.AddNew

'---populate all the fields in the new record from values from the
current record in the source table
for intCounter = 0 to rsSrc.Fields.Co unt-1
rsDest.Fields(i ntCounter) = rsSrc.Fields(in tCounter)
next intCounter
'---save the values in the new record
rsDest.Update

Okay, so then you have to call that for each record in the source
table, so you wrap it in a Do Until rsSrc.EOF thing and away you go.

Nov 13 '05 #5

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

Similar topics

1
5675
by: Thiko | last post by:
Hi I have a corrupt PK index on a table column. It is a unique PK. It needs to be dropped and recreated to cure the corruption. The table is on a backup database which is in replication having records added to it to keep the two databases in sync. Am I correct in think that if I:
8
12752
by: Amy DBA | last post by:
OK, I'm stumped now. I need help restoring a tablespace that has been marked offline. Here's a little background on the problem: 1) There was a hardware failure that caused the tablespace to become marked offline: State = 0x4000; Detailed explanation: Offline 2) I tried switching it back online and got this error: DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor...
4
5072
by: aaj | last post by:
Hi all I have been given a corrupt access 2000 backend and asked to salvage the data.(youve gussed it, no backup) On trying to open it just kicks me out saying its not a valid database file - so I can't even use the internal compact/repair function I have tried the usal stuff i.e. Trying to repair via another access program using dao
2
2910
by: j.mandala | last post by:
I have recently received a few calls from people using a split database I developed, reporting that data get corrupt and unreadable, or records 'disappear'. I am not sure that all the porblems are related, but the damage can sometimes be traced to a table that has two memo fields in it. The problems often begin on a particular day when the autonumber field for that table with suddenly jump up from something like 5000 to 1 million or so. I...
21
2694
by: Dan | last post by:
Hi, just ran into my first instance of a backend Access97 database not compacting. I'm getting the "MSACCESS.EXE has generated errors.." message on compact. I've narrowed it down to the largest table which cotains 600k of records. I've tried copying the database and trying to compact that -doesn't work. I've tried Repair and then compact which also doesn't work. I've tried to create a new database and import the tables but it flakes out...
5
2108
by: Jeff | last post by:
I'm sorry if I am appearing noobish, but I'm a C programmer that inhereted access because I'm the only "computer guy" in the office. Now I've found some problems that I fear maybe a corrupt database.... and I haven't the faintest of clue where to start when it comes to fixing this problem. Here is what happen: About a week ago the registrar came to me to ask if I could help her add a record to her training database. She told me that...
4
2390
by: nepdae | last post by:
Well, after reading and hunting all over the web, including here, I still haven't been successful in my attempts to resolve my situation. So, I thought maybe I'd just ask. Here's the situation: I have an Access 2000 database (~15 users), split into a front- and back-end. Each user has a local copy of a workgroup file and the data file is out on a server. The problem started when the IS department upgraded the server at night, touching...
4
2038
by: kruiz | last post by:
Hello, I'm having a big problem on one very important table in the system I'm developing. Everything started when I tried to insert some columns to this table, and AS400 DB2 told me that there was a corrupt trigger. So I recreated the triggers for that table and nothing happened. I've retaken this issue now and did a Generate SQL thru the iSeries Nav and got a nameless trigger. WHAT the hell I said! ... I was supposed to recreate that...
0
1395
by: Phil Stanton | last post by:
Sorry to repost this but I now seem to have the BE datbase corrupted. I have a FE, BE database on my home computer and a duplicate on the office computer. Both use Ak2 on Windows XP. The one at home appears normal. The BE consists of about 50 tables with numerous relationships and the FE 9 tables (fixed set up stuff) + the 50 linked table from the BE database. At home on the relationship view I see all the tables and their...
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.