[AccessD] Add-In Express 2009 for MS Office and .NET

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Fri Feb 12 14:32:35 CST 2010


Hi Max et al --

And here is the import part of code - just a working prototype to port to
Add-in in C#. I do not check object existence here etc.

As you can find in my another message I have also get exported MSys* tables
into XML - and that worked(?) well for all the MSys* tables (Access 2007).
Import didn't work even for MSysRelationships but one can use this
information to recreate relationships - just a note...

Thank you.

--
Shamil

P.S. Import code:

Option Compare Text
Option Explicit

Public Sub ImportObjects()
'
' 1. Imports Queries, Forms, Reports, Macros, Modules from
'     text files located \Objects subfolder
'
' 2. Imports Tables from
'     xml files with schema located \Objects subfolder
'

On Error GoTo errhandler

Dim strSourceFolder As String
Dim strSourceFileName As String
Dim app As Access.Application
Dim intObjType As Integer
Dim strObjectFileFullPath As String
Dim strObjectName As String

    Set app = Access.Application
    
    strSourceFolder = Access.Application.CurrentProject.path + "\Objects\"
    
    strSourceFileName = Dir(strSourceFolder, vbNormal)
    While (Len(strSourceFileName) > 0)
        Debug.Print getObjectTypeByFileName(strSourceFileName) & _
                    " - [" & _
                    getObjectNameFromFileName(strSourceFileName) & _
                    "] - " & _
                    strSourceFileName
        
        intObjType = getObjectTypeByFileName(strSourceFileName)
        
        If (intObjType <> -1) Then
            strObjectName = getObjectNameFromFileName(strSourceFileName)
            strObjectFileFullPath = strSourceFolder + strSourceFileName
        
            Select Case intObjType
            Case acTable:
                app.ImportXML strObjectFileFullPath, acStructureAndData
            Case acQuery, _
                 acForm, _
                 acReport, _
                 acMacro, _
                 acModule:
                   app.LoadFromText intObjType, _
                      strObjectName, _
                      strObjectFileFullPath
            Case Else
            End Select
        End If
        
        
        strSourceFileName = Dir
    Wend

     MsgBox ("Import DONE!")
   
exithere:
    Exit Sub
errhandler:
    MsgBox "Unhandled Error in sExportAllObjects(): " & Err.Number & vbCrLf
& Err.Description
    Resume exithere
    
End Sub

Private Function getObjectTypeByFileName(ByVal s As String) As Integer
Dim intObjType As Integer
    intObjType = -1
    If Left(s, 5) = "Table" Then intObjType = acTable
    If Left(s, 5) = "Query" Then intObjType = acQuery
    If Left(s, 4) = "Form" Then intObjType = acForm
    If Left(s, 6) = "Report" Then intObjType = acReport
    If Left(s, 5) = "Macro" Then intObjType = acMacro
    If Left(s, 6) = "Module" Then intObjType = acModule
    
    If intObjType = acTable And _
       InStr(s, "Schema.xml") > 0 Then intObjType = -1
       
    getObjectTypeByFileName = intObjType
End Function
     
Private Function getObjectNameFromFileName(ByVal s As String) As String
Dim strObjectName As String
Dim intPos As Integer
    If InStr(s, "Schema.xml") > 0 Then Exit Function
    
    s = Left(s, Len(s) - 4) ' cut fileExt
    intPos = InStrRev(s, "Table_")
    If (intPos = 0) Then intPos = InStrRev(s, "Query_")
    If (intPos = 0) Then intPos = InStrRev(s, "Form_")
    If (intPos = 0) Then intPos = InStrRev(s, "Report_")
    If (intPos = 0) Then intPos = InStrRev(s, "Macro_")
    If (intPos = 0) Then intPos = InStrRev(s, "Module_")

    If (intPos = 0) Then Exit Function
    
    intPos = InStr(intPos, s, "_")
    
    intPos = intPos + 1

    strObjectName = Mid(s, intPos)
    
    getObjectNameFromFileName = strObjectName
End Function


-----Original Message-----
From: Shamil Salakhetdinov [mailto:shamil at smsconsulting.spb.ru] 
Sent: Friday, February 12, 2010 11:18 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Add-In Express 2009 for MS Office and .NET

Hi Max --

Thank you for code samples - I plan to make it a bit different for first
version - something like the code in P.S. of this message (Export), and
Import will be posted in the other message.

Thank you.

--
Shamil

P.S. MS Access DB Export code (watch line wraps):

<<< snip >>>


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo
Sent: Friday, February 12, 2010 12:48 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Add-In Express 2009 for MS Office and .NET

Section 3 - Import

That's the lot now.  No form or user interface. I hope it works ok, seem ok
on my test system but caveat emptor as  always.

<<< snip >>> 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4861 (20100212) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru
 




More information about the AccessD mailing list