Creating a new Access database file at runtime.

Question:

Ho can I create a new Access database file for Elipse E3 at runtime?

Solution:

The Database is an Elipse E3 object used for storing the project’s information regarding Historics, Formulas, and Alarms. It can support the following formats: MDB (Microsoft Access), Oracle, and Microsoft SQL Server.

Microsoft Access is a database management system provided by Microsoft. It comes with the Microsoft Office package, and can use any information that has been stored in any data receptacle in the ODBC. If you’re still not sure which database model is the right one for your project, you can check out our article KB-31974: Databases: comparing models to help you make an informed decision.

In order to create a new Access database file from scratch at runtime, you must first follow a few guidelines. First of all, you will need to deactivate all database objects, such as: databases, Historics, and Storage. Then, you must edit the database file; only after you’ve made these changes that can you you reactivate these objects.

An important tip is: If you’re working in a query screen when the file is edited, you will need to remember to update the screen first.
The new file then can be created at runtime. To do so, you can follow the code we present below as an example. This code will deactivate the database’s objects, create a new file based on current data, and then reactivate the DB objects.
Set objHist = Application.GetObject("Hist1")​ Set objDB = Application.GetObject("BancoDados1")

​'Deactivate database objects
objDB.Deactivate()​
objHist.Deactivate()​
​
'Create a new file based on current data 
Call objDB.SetDBParameters("C:\CaminhoPastas\Dados_"&Day(Now)&"_"&Month(Now)&"_"&Year(Now)&".mdb", "", "", "")​
objDB.Save​
​
'Reactivate all database objects 
objDB.Activate()​
objHist.Activate()

 

Related articles:


 

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *