Avatar of Derek Brown
Derek BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Corruption?

I was just importing all front end objects into a new Blank DB and got this error. Anyone seen this before? All files are on a local pc with no association with any server.  .User generated image

Then after clicking OK I got thisUser generated image
Then I got thisUser generated image
Then this User generated image
Microsoft AccessPC

Avatar of undefined
Last Comment
John Tsioumpris
Avatar of Daniel Pineault
Daniel Pineault

These are signs of database corruption typically.

I'd try the undocumented SaveAsText and LoadFromText.

You could also try using John Viescas' FixBroken utility found at http://viescas.com/category/links/downloads/

Always work off of a copy of your db in case anything goes awry.
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I will try that Daniel  Cheers!
How about decompiling first the application..have you tried it.?
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Try piecewise import.
Tables, queries, modules, forms, and reports checking after each group.
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

When I have anything suspicious in Access I import all forms reports etc. to a new db. I think that decompiles, yes?

Had a look at Piecewise can't quite make out what it does?
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I have just saved my most complex form as text and re-imported it. Sent all to new db and compacted and compared it to a new db that I had done exactly the same with but without save form as text. I lost just over 100KB. Does this mean that there was corruption in the form?

Also I have this as my save as text and import:
Application.SaveAsText acForm, "Details", "C:\Z\Details.txt"
Application.LoadFromText acForm, "Details", "C:\Z\Details.txt"

Is there any way to automate this for all forms/Reports using something like:

    For Each obj In CurrentProject.AllForms
        Application.SaveAsText acForm, "[FormName]", "C:\Z\formname.txt"
    Next obj
Check this code
 Sub ExportFormsAsText()
Dim o As Object
Dim app As New Access.Application
Set app = CreateObject("Access.application")
app.OpenCurrentDatabase "C:\Projects\Access\test.accdb"
For Each o In app.DBEngine.Workspaces(0).Databases(0).Containers("forms").Documents

app.SaveAsText acForm, o.Name, "C:\Temp\" & o.Name & ".txt"
Next
End Sub

Open in new window


Just fill the path of your database in the app.OpenCurrentDatabase  and give it a try
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I put that in a new blank db added a blank form with a button. On click your code. It opens the db and is clearly processing but not saving form.text anywhere. If I run it from a form in the current database presumably it will stop when it gets to an open form with a button if not can I run the code from the current database and call the form Z so it saves forms until it reaches Z. Also what do I have wrong with code that it does not save

Private Sub Command0_Click()
Dim o As Object
Dim app As New Access.Application
Set app = CreateObject("Access.application")
app.OpenCurrentDatabase "C:\Z\ATesting\MyApp.mdb"
For Each o In app.DBEngine.Workspaces(0).Databases(0).Containers("forms").Documents
app.SaveAsText acForm, o.Name, "C:\Z\TextForms" & o.Name & ".txt"
Next
End Sub
Maybe permissions ?...in my test it worked just fine...
put a breakpoint on the app.save and check the output path....
Also ...maybe there is also an issue with the form_name..just put instead of the form name a counter to check..eg.
i=1
app.SaveAsText acform,o.Name,"C:\Z\Textforms " & i &".txt"
i=i+1
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I didn't put a "\" after TextForms indicating it was directory. Silly Me.

Fabulous John. That is such a time saver. Brilliant.

Of course there is no way to bring them back in as Load is there? That could be asking too much!! I only have 132 forms.

I am also going to try to Save Reports as Text there is 200 of those. All this just to try to eradicate invisible corruption!
You mean to Load them to your current db..just implement a file iterator and Load them one by one.
As for Reports the container name is ..."Reports"...:)
Quick hint
..as the export loop run save each exported filename to a table...use this table to populate - import the text Forms..
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks John

That's a bit beyond my knowledge uploading to a table.

How do I implement a file iterator?
The easy solution....:)
Private Sub Command0_Click()
Dim o As Object
Dim rst as DAO.Recordset
set rst = currentdb.openrecordset("FormRepo")
Dim app As New Access.Application
Set app = CreateObject("Access.application")
app.OpenCurrentDatabase "C:\Z\ATesting\MyApp.mdb"
with rst
For Each o In app.DBEngine.Workspaces(0).Databases(0).Containers("forms").Documents
app.SaveAsText acForm, o.Name, "C:\Z\TextForms" & o.Name & ".txt"
.AddNew
.Fields("FormName") = o.Name
.Fields("FormTextPath")="C:\Z\TextForms" & o.Name & ".txt"
.Update

Next
end with
rst.MoveFirst
While Not rst.EOF
Application.LoadFromText acForm, rst.Fields("FormName"), rst.Fields("FormTextPath")
rst.MoveNext
Wend
rst.Close
End Sub

Open in new window

So all you need is a table e.g. FormRepo with 2 fields
FormName to store the FormName
FormTextPath to store the path of the exported form
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

This is my best guess:

For each file in "FileFolder"
Application.LoadFromText acForm,  "o,name", "C:\Z\TextForm\ o.name.txt
Next file
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

My last question was sent before your reply. My thanks again I will try that now.
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

My God if that's easy you should work for me. Been on this for hours.  Help

Q1. Where is this code run from  the database that holds the FormRepo Yes? a button on a form?
Q2 . At line 5 are we creating a brand new database or opening an existing one
Q3 I have  the same address at line 10 and 13 but it errors at line 13

Option Compare Database

Private Sub Command1_Click()
Dim o As Object
Dim rst As DAO.Recordset
Set rst = CurrentDb.openrecordset("FormRepo")
Dim app As New Access.Application
Set app = CreateObject("Access.application")
app.OpenCurrentDatabase "C:\B\ARSTest\MyApp.mdb"  ' Address where we get files from
With rst
For Each o In app.DBEngine.Workspaces(0).Databases(0).Containers("forms").Documents
app.SaveAsText acForm, o.Name, "C:\B\ATesting\" & o.Name & ".txt" 'The address we are sending the text files to
.AddNew
.Fields("FormName") = o.Name
.Fields("FormTextPath") = "C:\B\ATesting\" & o.Name & ".txt"
.Update

Next
End With
rst.MoveFirst
While Not rst.EOF
Application.LoadFromText acForm, rst.Fields("FormName"), rst.Fields("FormTextPath")
rst.MoveNext
Wend
rst.Close
End Sub
1. Just create a form and put a button...on the click event just put the code
2.We are creating a new instance of Access and opening an existing database
3.Have you created a table named FormRepo with 2 fields ?
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks John

Yes, they are in the same new database that I created for the form with button.

Sorry I should know this after 20 years of access but when you say a new instance is that a new db or does it just mean we have started MS Access

Yes I have also created a two field table. No Key field.

I don't know why it errors at line 13?
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I just cannot see how we can be saving forms from line 10 and importing them to the same place at 13. I must be missing something. Wouldn't be the first time.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Ah now I see it we are not loading from text in line 13 we are just adding the text file name to the table.
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Wow just got that to work. Only took 6 hours. Now I will try Reports
Hope you got the most of your work.
Avatar of Derek Brown
Derek Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Yes works brilliantly when I finally got it. Just a thought can you or would you save tables to text. Is there any point?
Haven't tried it but i think the Containers support Tables...if not try the version i send you for Queries and check if substituting QueryDefs to TableDefs works.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo