473,546 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code To Transfer VBA Modules

72 New Member
Hi,

I have the below code to transfer code modules between Access database files. I have three problems, only one of which is annoying.

a) How do you prevent the Save As box from appearing when the instance of Access is closed? I've tried the acQuitSaveAll as well as the acCmdCompileAnd SaveAllModules route.

b) The On Error line was added when the code was in Access 2003, when I was getting an error message regarding a bad DLL reference when the code hit the Exit Sub at the end. The message description said to check the parameter types or values being passed. This occured consistently but the error would happen, stop the code, I'd step the code on and no error would occur, so I put a Resume Next there to step past it. Under Access 2000 however, this does not occur at all. Any ideas as to why?

c) The code does not consistently perform the import. Stepping through it appears to do what it's supposed to, and if I exit early then it prompts me to save what its done so far. However, when I let it run on a series of seven other databases, some of them don't seem to correctly do the first handful of modules. At first I thought this was to do with the Save As not appearing for those modules so it did not save them, but as a strange quirk, the more times I run this on the same files, the more modules don't get transferred. If it is not to do with the Save As box, I have a suspicion this is to do with the loops and their indexes in the components. Any suggestions?

Regards,
Rob.


Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'Stand-alone function to synchronise all files in the same directory as this one.
  5. Public Sub RunSynchBatch()
  6.     Call DoBatchSynchronise(Access.Application)
  7. End Sub
  8.  
  9. 'Cycles through databases in a given directory and performs a synch with this file.
  10. 'If sCycleDir is not supplied, you will be prompted.
  11. Public Sub DoBatchSynchronise(oExportFrom As Access.Application, Optional sCycleDir As String = "")
  12.     Dim nLoop As Integer
  13.  
  14.     If sCycleDir = "" Then
  15.         'Sets the default entry in the prompt to the same directory as this file.
  16.         With oExportFrom.CurrentDb
  17.             sCycleDir = Dir(.Name, vbDirectory)
  18.             sCycleDir = Left(.Name, Len(.Name) - Len(sCycleDir))
  19.         End With
  20.  
  21.         sCycleDir = InputBox("Please enter the full path of the directory you wish to update:", "Update Directory", sCycleDir)
  22.     End If
  23.  
  24.     With Application.FileSearch
  25.         .NewSearch
  26.         .FileType = msoFileTypeDatabases
  27.         .LookIn = sCycleDir
  28.  
  29.         If .Execute > 0 Then
  30.             For nLoop = 1 To .FoundFiles.Count
  31.                 'For each database found, so long as it is not this one, transfers the code.
  32.                 If .FoundFiles(nLoop) <> oExportFrom.CurrentDb.Name Then Call DoSynchroniseCode(oExportFrom, .FoundFiles(nLoop))
  33.             Next nLoop
  34.         End If
  35.     End With
  36. End Sub
  37.  
  38. 'Performs a one-shot export of the code modules in the database open in the oExportFrom instance
  39. 'of Access to the file specified by sSendTo.
  40. Public Sub DoSynchroniseCode(oExportFrom As Access.Application, sSendTo As String)
  41.     Dim oAccess As Access.Application
  42.  
  43.     Call oExportFrom.DoCmd.SetWarnings(False)
  44.  
  45.     'Checks that the file specified is really an Access database.
  46.     If Right(sSendTo, Len(sSendTo) - InStrRev(sSendTo, ".")) = "mdb" Then
  47.         'Opens a new instance of Access and opens the specified database.
  48.         Set oAccess = New Access.Application
  49.  
  50.         Call oAccess.DoCmd.SetWarnings(False)
  51.         Call oAccess.OpenCurrentDatabase(sSendTo)
  52.         Call DoAccessImport(oExportFrom, oAccess)
  53.         Call oAccess.DoCmd.RunCommand(acCmdCompileAndSaveAllModules)
  54.         Call oAccess.Quit(acQuitSaveAll)
  55.     End If
  56.  
  57.     Call oExportFrom.DoCmd.SetWarnings(True)
  58. End Sub
  59.  
  60. 'Exports all the code files in oExportFrom and imports them into oImportTo.
  61. Private Sub DoAccessImport(oExportFrom As Access.Application, oImportTo As Access.Application)
  62.     Dim sStore As String
  63.     Dim nLoop As Integer, nComps As Integer
  64.  
  65.     'Uses the location of the oExportFrom file to create a temporary directory to store the
  66.     'exported code.
  67.     With oExportFrom.CurrentDb
  68.         sStore = Dir(.Name, vbDirectory)
  69.         sStore = Left(.Name, Len(.Name) - Len(sStore)) & PATH_SYNCH_DIR & "\"
  70.     End With
  71.  
  72.     If Len(FileSystem.Dir(sStore, vbDirectory)) <= 0 Then Call FileSystem.MkDir(sStore)
  73.  
  74.     With oExportFrom.VBE
  75.         'For each project that exists in the database, cycles through the components which exist
  76.         'as part of it.
  77.         For nLoop = 1 To .VBProjects.Count
  78.             With .VBProjects(nLoop).VBComponents
  79.                 For nComps = 1 To .Count
  80.                     With .Item(nComps)
  81.                         'Currently only performs this with Standard and Class modules.
  82.                         If .Type = vbext_ct_StdModule Or .Type = vbext_ct_ClassModule Then
  83.                             'Exports the module into a text file so it can be imported.
  84.                             Call .Export(sStore & .Name & ".txt")
  85.                             Call DoImportModule(oImportTo, .Name, sStore)
  86.                         End If
  87.                     End With
  88.                 Next nComps
  89.             End With
  90.         Next nLoop
  91.     End With
  92. End Sub
  93.  
  94. 'Searches through the target database to check if the module being transferred already exists.
  95. 'If it does, then removes the module before importing the one exported from the main database.
  96. Private Sub DoImportModule(oSearch As Access.Application, sName As String, sStoreDir As String)
  97.     On Error Resume Next
  98.  
  99.     Dim nLoop As Integer, nComps As Integer
  100.  
  101.     With oSearch.VBE
  102.         'NOTE: If you have more than one project in the target database, this will import the
  103.         'requested code module into all of them.
  104.         For nLoop = 1 To .VBProjects.Count
  105.             With .VBProjects(nLoop).VBComponents
  106.                 For nComps = 1 To .Count
  107.                     'Checks that it has found a module of the same name, and that it is a
  108.                     'standard or class module.
  109.                     If .Item(nComps).Name = sName And _
  110.                        (.Item(nComps).Type = vbext_ct_StdModule Or _
  111.                         .Item(nComps).Type = vbext_ct_ClassModule) Then
  112.                         'Removes the module so that when the import is done you don't get auto-
  113.                         'numbered versions of the module.
  114.                         Call .Remove(.Item(nComps))
  115.                         Exit For
  116.                     End If
  117.                 Next nComps
  118.  
  119.                 Call .Import(sStoreDir & sName & ".txt")
  120.             End With
  121.         Next nLoop
  122.     End With
  123. End Sub
  124.  
Jul 3 '07 #1
0 1596

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1765
by: joieva | last post by:
I would like to know how we can transfer data through a secured channel to a non-secured site. I am designing an e-commerce site and getting data from secured site database(on a firewall) and display to my site. Thank you.
5
5550
by: Glauco | last post by:
hi to all, i'm planning to make a way to transfer file with python. I would like to make the transfer using some crypto api, to make the channel secure. i don't want to write a wrapper to ftp or to scp i just want to make a new protocol, for a little application. i took a quick look to some cryptographic modules available in python...
242
13175
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on...
17
25390
by: Lauren Wilson | last post by:
Hi folks, Can someone point me to some resources on how to control FTP sessions from and Access application with VBA? Many thanks for all help. --LW.
6
1833
by: Shaun Wilde | last post by:
I am trying to handle a 404 errors and redirect them to the correct page based on criteria I was hoping to catch the error in the global error handler and forward via Server.Transfer to the correct page such that it would appear to be the page requested. ow this does work to a fashion but it seems that I don't have access to the session...
2
1406
by: Bart Van der Donck | last post by:
Hello, I'm posting the software for one-FAQ-a-day as described on http://tinyurl.com/qcxw7 (comp.lang.javascript, July 18 2006, titled "CLJ newsgroup FAQ) and on http://tinyurl.com/ppt2s (comp.lang.javascript, July 22 2006, titled "Automation of comp.lang.javascript FAQ")
2
6439
by: Valli | last post by:
Hi, My project contains 20 htm pages. All these page conatins login button where the click of login button transfers to login.htm page. All these modules were designed by my colleague. My part is to design aspx pages & include that with htm pages. I have designed the login page named as Default.aspx. Now this Default.aspx must be...
1
4828
by: Saurabh | last post by:
Dear All, Can anyone tell me, how to write such a program that can transfer files (either binary or text) behind NAT devices( such as for computers behind firewalls and routers and other NAT devices) using TCP socket programming. I have a mechanism through which the public IP of the router and Port number will be forwarded to me. But...
1
5773
by: archdin | last post by:
Hello experts, I m working in SAP. But this time i m working on program of weighbridge. An ABAP application is developed to get the vehicle and material information along with the gross and tare weight of vehicles. The application executes a visual basic program on the local PC that captures U] weight data from the Avery digitizer and...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.