Larry said:
If there is something gone wrong in the Form, I wouldn't trust anything
short of (1) re-creating the Form from scratch or (2) using SaveAsText and
LoadFromText (those are about the most recommended, and best
unofficially-documented but officially-undocumented features of Access) to
take the Form to text, then re-create it. Most any other approach still
leaves you exposed to transferring whatever has gone wrong into the "new"
Form with something that you copy.
But, as Jeff pointed out, there are different kinds of corruption, and
multiple possibilities as a cause.
Larry Linson
Microsoft Office Access MVP
The Save module code below was adapted (rather quickly) from a post by
Lyle Fairfield. Note that the link at his web site for this doesn't
work anymore. I don't know who did the Import code (I modified it
slightly).
Public Sub SaveFormsAsText(path As String)
Dim Filename As String
Dim strName As String
Dim theForm As Form
Dim ctnr As Container
Dim MyDB As DAO.Database
Dim DocForm As Document
Set MyDB = CurrentDb
For Each ctnr In MyDB.Containers
If ctnr.Name = "Forms" Then
For Each DocForm In ctnr.Documents
strName = DocForm.Name
Filename = path & strName & Format(Now(), "yyyymmddhhnn") & ".txt"
SaveAsText acForm, strName, Filename
DoEvents
Next DocForm
End If
Next ctnr
DoEvents
MsgBox "All Done Saving Forms as Text"
End Sub
Public Sub ImportDatabaseObjects()
On Error GoTo Err_ImportDatabaseObjects
Dim strFilename As String
Dim ObjName As String
Dim ObjType As String
Dim acObjType As Integer
Dim Index As Integer
Dim ImportLocation As String
Dim ImportDir As String
ImportLocation = "C:\MyExport\*.*"
strFilename = Dir(ImportLocation)
Do
ImportDir = "C:\MyExport\"
ObjName = Left(strFilename, Len(strFilename) - 16)
strFilename = ImportDir & strFilename
Application.LoadFromText acForm, ObjName, strFilename
strFilename = Dir
Loop Until strFilename = ""
Exit_ImportDatabaseObjects:
Exit Sub
Err_ImportDatabaseObjects:
'Debug.Print ObjName & "." & ObjType & "." & Err.Number & "." &
End Sub
How I used it:
Private Sub cmdImportForms_Click()
Call ImportDatabaseObjects
MsgBox ("Done Importing Forms.")
End Sub
Private Sub cmdSaveFormsAsText_Click()
Call SaveFormsAsText("C:\MyExport")
End Sub
After exporting, I just put the files I wanted to import into the
directory. A smoother way would be to have a form select the directory
using a file picker and populate a listbox for the user to choose which
form text files to import. The problem I had was that a call to a Class
Module I used to maintain a global date value for a pop-up calendar form
wouldn't convert to A2K3. Even though the database ran fine in A97, a
message came up saying that the conversion could not be accomplished
because the VBA code is corrupt. Replacing the call to the Class Module
with a global date variable solved the problem for now. Reconstituting
the forms from text allowed me to see which form caused the problem. As
Larry pointed out, SaveAsText and LoadFromText are officially
undocumented, but they managed to help me solve that problem.
James A. Fortune
(e-mail address removed)