Public Sub create_Database()
' creates blank database and copies this module into it
Dim str_Database As String ' Location of database to create
Dim str_Module As String ' module to copy to it
Dim app As Access.Application ' instance of Access to create blank database
str_Database = "C:\Test\Blank.accdb"
str_Module = "TestModule"
Set app = New Access.Application
app.DBEngine.CreateDatabase str_Database, DB_LANG_GENERAL
app.Quit
Set app = Nothing
' creates blank database in same directory
DoCmd.CopyObject str_Database, str_Module, acModule, str_Module
' moves module to blank database
End Sub
Sub NewDatabaseCreate()
10 On Error GoTo NewDatabaseCreate_Error
Dim dbNew As DAO.Database
Dim strDB As String
20 strDB = Environ("LOCALAPPDATA") & "\SaveandLOADSep16B.accdb"
30 Set dbNew = DBEngine.CreateDatabase(strDB, dbLangGeneral)
40 Debug.Print "Database Created: " & strDB
50 dbNew.Close
60 On Error GoTo 0
NewDatabaseCreate_Exit:
70 Exit Sub
NewDatabaseCreate_Error:
80 MsgBox "Error " & Err.Number & " (" & Err.Description & "), line " & Erl & " in Procedure NewDatabaseCreate" _
& " Module SaveAndLoadAdmin "
90 GoTo NewDatabaseCreate_Exit
End Sub
Sub NewDatabaseAddModule()
10 On Error GoTo NewDatabaseAddModule_Error
Dim dbNew As DAO.Database
Dim strDB As String
20 strDB = Environ("LOCALAPPDATA") & "\SaveandLOADSep16B.accdb"
30 Set dbNew = DBEngine.OpenDatabase(strDB)
40 Debug.Print "Database Opened: " & strDB
50 LoadFromText acModule, "SAVEandLOad", Environ("LOCALAPPDATA") & "\SaveAndLoad.txt"
60 DoEvents
70 Debug.Print "Module Loaded from Text: " & Environ("LOCALAPPDATA") & "\SaveAndLoad.txt"
80 dbNew.Close
90 On Error GoTo 0
NewDatabaseAddModule_Exit:
100 Exit Sub
NewDatabaseAddModule_Error:
110 MsgBox "Error " & Err.Number & " (" & Err.Description & "), line " & Erl & " in Procedure NewDatabaseAddModule" _
& " Module SaveAndLoadAdmin "
120 GoTo NewDatabaseAddModule_Exit
End Sub
Jack,Update, I used plog's Docmd.Copyobject and the module was copied/loaded successfully. Onto to the next step.
Sub MakeACCDE(strPathSource As String, strPathDest As String)
'Colin Riddington (isladogs)
'Last updated 21/06/2020
'The external database MUST:
'1. be created in the same version of Access
'2. be in a trusted folder
'3. compile without error
'4. be closed
'This code requires that the folder already exists - easily modified to create a folder if not
'If the ACCDE already exists it is overwritten
'=================================
Dim objAccess
On Error GoTo Err_Handler
'create the ACCDB file (if it doesn't already exist)
DBEngine.CreateDatabase strPathSource, DB_LANG_GENERAL
'Create the Access Automation object
Set objAccess = CreateObject("Access.Application")
'Now call the undocumented SysCmd function
' objAccess.SysCmd 603, strPathSource, strPathDest 'this gives err 7952 - illegal function call
' ...fix by explicitly setting the paths as strings
objAccess.SysCmd 603, CStr(strPathSource), CStr(strPathDest)
Set objAccess = Nothing
Exit_Handler:
Exit Sub
Err_Handler:
If Err = 3204 Then Resume Next 'source db already exists
MsgBox "Error " & Err & " : " & Err.description
Resume Exit_Handler
End Sub
Paul,Jack,
How did you specify the location of the text file?
Could you post the code please?
Sorry, I meant loading it into the new DB, if you used Copyobject?Paul,
SaveAsText acModule, "SaveAndLoad", Environ("LOCALAPPDATA") & "\SaveAndLoad.txt"
Private Sub cmdCaseFlow_Click()
' This code supplied by Ashley Baker instead of using clipboard
Const dbPath As String = "C:\Program Files\PPI Caseflow\PPI Caseflow.mde"
On Error GoTo Err_Handler
Dim appAccess As Access.Application
Set appAccess = GetObject(dbPath)
' appAccess.Visible = True
appAccess.DoCmd.OpenForm "frm_Caseflow"
appAccess.Forms!frm_Caseflow!ub_Charter = Me.txtPrev_Ref
appAccess.Forms.frm_Caseflow!chk_RememberSelection = True
appAccess.Forms!frm_Caseflow.Refresh
appAccess.DoCmd.RunCommand acCmdAppMinimize
appAccess.DoCmd.RunCommand acCmdAppMaximize
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Handler
End Sub
There are two different conversations in this thread, have to be careful which to reply to.Paul,
I've hit a couple of snags at the moment.
-can't copyobject to the new database and keep all references??
-need to add a reference for the scripting runtime
-need to sort out how to name a reference (common name) had it working recently??
-rethinking overall approach