Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Fri Feb 12 14:18:22 CST 2010
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): Option Compare Text Option Explicit Public Sub ExportObjects() ' ' 1. Exports Queries, Forms, Reports, Macros, Modules as ' text files into \Objects subfolder ' ' 2. Exports Tables as ' xml files with schema into \Objects subfolder ' ' 3. Exports MSys* tables as ' xml files with schema into \Objects\MSysTables subfolder ' On Error GoTo errhandler Dim app As Access.Application Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim strTargetFolder As String Dim strTargetFileName As String Dim strObjectFileFullPath As String Dim strObjectName As String Set app = Access.Application strTargetFolder = Access.Application.CurrentProject.path + "\Objects\" Set dbs = app.CurrentDb Set rst = dbs.OpenRecordset(exportedObjectsSql, dbOpenForwardOnly) While Not (rst.EOF) Select Case rst![AcObjectType].Value Case acTable: strTargetFileName = _ rst![ObjectTypeName].Value + "_" + _ rst![ObjectName].Value If (Left(rst![ObjectName].Value, 4) <> "MSys") Then app.ExportXML acTable, _ rst![ObjectName].Value, _ strTargetFileName + ".xml", _ strTargetFileName + "Schema.xml" Else On Error Resume Next app.ExportXML acTable, _ rst![ObjectName].Value, _ strTargetFolder + "MSysTables\" + strTargetFileName + ".xml", _ strTargetFolder + "MSysTables\" + strTargetFileName + "Schema.xml" On Error GoTo errhandler End If Case acQuery, _ acForm, _ acReport, _ acMacro, _ acModule: strTargetFileName = rst![ObjectTypeName].Value + _ "_" + rst![ObjectName].Value + ".txt" app.SaveAsText _ rst![AcObjectType].Value, _ rst![ObjectName].Value, _ strTargetFolder + strTargetFileName Case Else End Select rst.MoveNext Wend rst.Close MsgBox ("Export DONE!") exithere: Exit Sub errhandler: MsgBox "Unhandled Error in sExportAllObjects(): " & Err.Number & vbCrLf & Err.Description Resume exithere End Sub Private Property Get exportedObjectsSql() Dim strSql As String strSql = _ "SELECT " + _ " Switch( " + _ " [Type]=1,0, " + _ " [Type]=5,1, " + _ " [Type]=-32768,2, " + _ " [Type]=-32764,3, " + _ " [Type]=-32766,4, " + _ " [Type]=-32761,5) AS acObjectType, " + _ " Choose( " + _ " [acObjectType]+1,'Table','Query','Form','Report','Macro','Module') AS ObjectTypeName, " + _ " MSysObjects.Name as ObjectName " + _ " FROM MSysObjects " + _ " WHERE " + _ " ((Not (Switch( " + _ " [Type]=1,0,[Type]=5,1,[Type]=-32768,2,[Type]=-32764,3,[Type]=-32766,4,[Type] =-32761,5)) Is Null) AND ((MSysObjects.Name) Not Like '~*')) " + _ " ORDER BY Switch([Type]=1,0,[Type]=5,1,[Type]=-32768,2,[Type]=-32764,3,[Type]=-32766,4 ,[Type]=-32761,5), MSysObjects.Name;" exportedObjectsSql = strSql End Property -----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