msaccess-vcs-integration
msaccess-vcs-integration copied to clipboard
ImportAllSource fails for objects other than modules
I have exported one my existing projects and then tried to re-import it into an empty project. The ImportObject sub fails at this line [Application.LoadFromText obj_type_num, obj_name, TempFile()]. I modified the sub to report the error and resume next and a list of files is created reporting the errors. The errors look like [Microsoft Access encountered an error while importing the object 'ChargeOutRate'.
Error encountered at line 4. Expected: End of file. Found: Name.]
If I hardwire the Application.LoadfromText method with attributes, then I get "Microsoft Access cannot create the output file" which is confusing when one is trying to import.
The failure of the LoadFromText method is known see http://stackoverflow.com/questions/208397/loadfromtext-gives-error-2285-microsoft-office-access-cant-create-the-output-f
I guess that is is triggered by projects which were created in one version of ms-access being converted into a later edition of ms-access as it is not possible to reimport objects back into the database they were exported from.
This is not a show stopper as the modules are where the really important code is and the do import. I can still detect changes to other objects and manually import the objects.
Think that the first change to the project should be to add some error handling that can jump over objects that cannot be imported and which logs the failed imports.
I got the code working and can now export all form, report, macro and modules and re-import them into a new database and regenerate the whole application. For some reason the queries did not import and the tables have to be brought over manually anyway. I am using ms-access 2010 and Git Extensions. For some reason, queries did not import but I will work on that. From other experience, the queries are evaluated when imported and this will fail if tables are not imported first. The exported query code looks good so the query code is not likely to be the issue. Note also that some small issues are such as forms not linking properly to their class modules also occur, but these are easily ironed out. Compile the application and compact and repair it. Relinking class modules can be triggered by opening and event procedure and typing in a space on an empty line or any other edit and then compiling.
One critical line of code need to be inserted into the Sanitise text files procedure. The fixed procedure is below. The problem is that some lines with the word BEGIN are skipped by the original procedure. The inserted lines are flagged with the following comment, "' This line needs to be added"
' For each *.txt in Path
, find and remove a number of problematic but
' unnecessary lines of VB code that are inserted automatically by the
' Access GUI and change often (we don't want these lines of code in
' version control).
Private Sub SanitizeTextFiles(Path As String, Ext As String)
Dim fso, InFile, OutFile, FileName As String, txt As String, obj_name As String
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = Dir(Path & "*." & Ext)
Do Until Len(FileName) = 0
obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
Set InFile = fso.OpenTextFile(Path & obj_name & "." & Ext, ForReading)
Set OutFile = fso.CreateTextFile(Path & obj_name & ".sanitize", True)
Do Until InFile.AtEndOfStream
txt = InFile.ReadLine
If Left(txt, 10) = "Checksum =" Then
' Skip lines starting with Checksum
ElseIf InStr(txt, "NoSaveCTIWhenDisabled =1") Then
' Skip lines containning NoSaveCTIWhenDisabled
ElseIf InStr(txt, "Begin") > 0 Then
If _
InStr(txt, "PrtDevNames =") > 0 Or _
InStr(txt, "PrtDevNamesW =") > 0 Or _
InStr(txt, "PrtDevModeW =") > 0 Or _
InStr(txt, "PrtDevMode =") > 0 _
Then
' skip this block of code
Do Until InFile.AtEndOfStream
txt = InFile.ReadLine
If InStr(txt, "End") Then Exit Do
Loop
ElseIf AggressiveSanitize And ( _
InStr(txt, "dbLongBinary ""DOL"" =") > 0 Or _
InStr(txt, "NameMap") > 0 Or _
InStr(txt, "GUID") > 0 _
) Then
' skip this block of code
Do Until InFile.AtEndOfStream
txt = InFile.ReadLine
If InStr(txt, "End") Then Exit Do
Loop
Else ' This line needs to be added
OutFile.WriteLine txt ' This line needs to be added
End If ' This line needs to be added
Else
OutFile.WriteLine txt
End If
Loop
OutFile.Close
InFile.Close
FileName = Dir()
Loop
FileName = Dir(Path & "*." & Ext)
Do Until Len(FileName) = 0
obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
Kill Path & obj_name & "." & Ext
Name Path & obj_name & ".sanitize" As Path & obj_name & "." & Ext
FileName = Dir()
Loop
End Sub
I added some code which stores table structures and re-imports them almost loss free (some relational cascading stuff has to be fixed manually). The exported files are SQL. Hope it is going to be pulled.
Hi ArminBra, I will install and test your latest version. I see your brilliant work as the means to combine the power of ms-access with the the power of GIT. In a single developer context, it allows me to send out applications to clients then keep developing the application in the knowledge that if the client application comes back, I can use GIT to check it for changes the client may have made and so see what changes I have made between the version they have and the current build. I can't overstate how good this is to be able to do this. Thanks for your hard work.
Cheers,
Andrew
Thank you for your very kind reply. Wouldn't have come so far without your basis. I think we have something that is serialising the db content only. Found out the newer ...x office formats can simply be handled by unzipping them. But with a lot of overhead. Regards Armin