Macropheliac
Registered User.
- Local time
- Today, 14:50
- Joined
- Mar 13, 2013
- Messages
- 39
Hello all!
I'm in the midst of building a fairly extensive database for my company. I've split into front end and back end, but I've become concerned about the front end bloating as well as updating the front end as constant changes and additions will be required. In other words, forms, tables, queries, etc. will have to be added periodically.
In order to make the updating easier, I thought I would save the objects to text files and have the front end load the objects. Therefore, all that would have to be replaced are the text files. However, the constant removing and loading of objects produces quite a bit of bloat. Therefore, I thought I'd figure a way to create a new front end on each open. I saw a few sites about distributing and such, but none of them seemed quite right for me, so I came up with the following...
The CreateFE procedure creates a new database using the CreateNewDatabase function. Then, the OpenDatabase procedure opens the new database using the Shell command, followed by closing the current database using the CloseFECreator function.
This all works well. However, the problem arises when I try to run this when opening the FECreator database. I created an AutoExec macro to do this. It works fine when I open and run manually, but the application hangs and closes when run through AutoExec. I even tried running via a form that was set to start up when opening but the result was the same.
Any ideas as to why this is or how I can go about this differently would be greatly appreciated.
I'm in the midst of building a fairly extensive database for my company. I've split into front end and back end, but I've become concerned about the front end bloating as well as updating the front end as constant changes and additions will be required. In other words, forms, tables, queries, etc. will have to be added periodically.
In order to make the updating easier, I thought I would save the objects to text files and have the front end load the objects. Therefore, all that would have to be replaced are the text files. However, the constant removing and loading of objects produces quite a bit of bloat. Therefore, I thought I'd figure a way to create a new front end on each open. I saw a few sites about distributing and such, but none of them seemed quite right for me, so I came up with the following...
Code:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub OpenDatabase()
Dim strDB As String
strDB = CurrentProject.Path & "/Timekeeper_FE.accdb"
ShellExecute 0, vbNullString, strDB, vbNullString, vbNullString, 3
End Sub
Sub CreateFE()
Dim acApp As Access.Application
CreateNewDatabase CurrentProject.Path, "Timekeeper_FE.accdb"
DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentProject.Path & "/Timekeeper_FE.accdb", acModule, "Module3", "Module3"
Set acApp = CreateObject("Access.Application")
acApp.OpenCurrentDatabase CurrentProject.Path & "/Timekeeper_FE.accdb"
acApp.Run "ImportForms"
acApp.DoCmd.Quit
End Sub
Public Function CreateNewDatabase(strPath As String, strName As String) As Database
Dim WS As Workspace, db As Database, strFullName As String
strFullName = strPath & "/" & strName
Set WS = DBEngine.Workspaces(0)
If Dir(strFullName) <> "" Then Kill strFullName
Set db = WS.CreateDatabase(strFullName, dbLangGeneral)
End Function
Public Function RunCreateFE()
CreateFE
End Function
Public Function CloseFECreator()
DoCmd.Quit
End Function
Public Function RunOpenDatabase()
OpenDatabase
End Function
Sub ImportForms() ' Shortened version
Dim fName As String
fName = "frmCategory"
LoadForm fName
fName = "frmCraftCode"
LoadForm fName
fName = "frmCraftEntry"
LoadForm fName
fName = "frmDateSelector"
LoadForm fName
fName = "frmDiscipline"
LoadForm fName
End Sub
The CreateFE procedure creates a new database using the CreateNewDatabase function. Then, the OpenDatabase procedure opens the new database using the Shell command, followed by closing the current database using the CloseFECreator function.
This all works well. However, the problem arises when I try to run this when opening the FECreator database. I created an AutoExec macro to do this. It works fine when I open and run manually, but the application hangs and closes when run through AutoExec. I even tried running via a form that was set to start up when opening but the result was the same.
Any ideas as to why this is or how I can go about this differently would be greatly appreciated.