* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Interfacing possibilities in Microsoft Access, using external data
Concurrency control wikipedia , lookup
Oracle Database wikipedia , lookup
Team Foundation Server wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Ingres (database) wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Clusterpoint wikipedia , lookup
Microsoft Access wikipedia , lookup
Relational model wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Papers of the Sibiu Alma Mater University Conference, Fifth Edition, 24–26 March 2011, Sibiu – Volume 1 Interfacing possibilities in Microsoft Access, using external data sources and Visual Basic for Application code sequences Ilie ŞUFANĂ Sibiu Alma Mater University, 57 Somesului St., 550003 Sibiu, Romania Tel. / Fax: +40 0269 250008, e-mail: [email protected] Abstract This article presents a few possibilities of interfacing provided by Microsoft Access, containing information coming from other sources, also knowing the fact that Microsoft Access allows using many types of data from other data bases: table computing sheets, text files or by means of these being copied or linked to these data. Keywords: Microsoft Access, Microsoft SQL Server, Queries, Forms, Reports, Macrocommands, Modules. Rezumat Acest articol prezintă câteva posibilităţi de interfaţare oferite de Microsoft Access, conţinând informaţii provenite din alte surse, ştiind că Microsoft Access permite folosirea mai multor tipuri de date din alte baze de date: foi de calcul tabelare, fişiere text sau prin copierea acestora sau relaţionarea lor la aceste date. Cuvinte-cheie: Microsoft Access, Microsoft SQL Server, Interogări, Formulare, Rapoarte, Macrocomenzi, Module 1. Introduction Microsft Acess provides the interfacing possibility using data stored outside the current database. It can be data from another Microsoft Access database as well as data stored in different files, including files from Foxpro, dBase, Paradox, Lotus, Excel and others. Access is an excelent product which provides powerfull and efficient methods for data presentation, including external data. Access data is stored in external files due to different reasons. For example, large databases can be administrated more efficiently on a back-end database server like Microsoft SQL SERVER. Frequently, data is stored in Foxpro, dBase or Paradox files because it is used by older applications written in this programming languages. Access data can be stored in other databases, different from the one from your application. No matter how the data is stored, it is necessary to understand how to use this data using the user interface, as well as how to manipulate external data using VBA modules. Therefore we can access data from other sources, we can create interrogations, forms and reports using this data. 2. Discussion 2.1. Creating the interface using external data For accessing external data we have two possibilities. We can access the data by creating a link from our Access database or we can directly open a data source. Whenever it is possible we would like to create a link with external files. By doing so we will increase the performance of the the external data manipulation process. 2.2. Creating a link with an external table Links with external data can be easily created using front-end instruments provided by Access. For creating a link with a table from another Access database or from any other database, right click on one of the database label and then select 216 Ilie ŞUFANĂ - Interfacing possibilities in Microsoft Access, using external data sources and VBA code sequences the Link Tables option or the Get External Data (receives external data) from the File tab and then choose Link Tables. From the dialog box which will appear on the screen, select the name and the type of the file with ehich you want to link. After selecting a file and after you fill the required information, you have to click on the Link button. A Link Tables dialog box will appear which allows you to select the table with which you wish to create a link. After selecting the table and after pressing OK, the table you selected will appear on the screen, among the other tables from your database. You can create queries, forms, reports, macro commands and modules which will work with your attached table. You can modify only certain properties of the table. You cannot change the structure of the table you attached. For example, you cannot change the type or length of a field. But you can add a title to a certain field. If you try to modify the table’s structure, a dialog box will appear and by clicking „Yes” in the dialog box you are permitted to change only certain properties of the attached table. However, after you visualize the table in the Design mode, Access informes you on the properties you can and cannot modify. Every property that cannot be modified has the „This property cannot be modified in linked tables”. For creating a link with an external table, using VBA instructions, you need to follow four steps: a) Open your Microsoft Access database, which will contain the link with the external table b) Create a new table definition using the external data source. c) Set the configuration values for the external database and for the external table. d) Link the table to the database by adding the table definition. Here is an example of the four steps, using VBA instructions: Sub ConnectToFox(sDirName As String, sTableName As String, sAccessTable) Dim db As Database Dim td As TableDef Set db = CurrentDb Set td = td.CreateTableDef(sAccessTable) td.Conect = “FoxPro 2.6;DATABASE=“ & sDirName td.SourceTableName = sTableName db.TableDefs.Append td End Sub The subroutine can be called in the following way: Call ConnectToFox (“C:\Fpw26\Tutorial” , “customer” ,”tblCustomer” ) The ConnectToFox subroutine, receives three parameters when it is called. The first one is the name of the folder in which FoxPro is stored. The second one is the name of the file with which you wish to link, without the DBF extension. And the third parameter is the name of the table you which to create. The subroutine creates two object variables. The first one is of database type and the second one is of table definition type. After this, it sends the database type object to the current database and after that it creates a table definition with the name tblCustomer. For this table definition it creates a connection string. The string specified in the subroutine indicates that you will create a link with a FoxPro 2.6 table. The name of the folder acts the same as the database with which you want to link. After configuring the definition table’s Connect property, you are ready to insert the name of the table with which you want to create a link. This is the name of the FoxPro file. In the end you are ready to add the table definition to your own database. For creating a link with an Access table, stored in an other database, the following subroutine will be called: Sub ConnectToAccess(sDBName As String, sTableName As String, sAccessTable) Dim db As Database Dim td As TableDef Set db = CurrentDb Set td = td.CreateTableDef(sAccessTable) td.Conect = “;DATABASE=“ & sDBName td.SourceTableName = sTableName db.TableDefs.Append td End Sub It can be seen that the database with which you are trying to connect isn’t specified. All the other operations from the subroutine are identical with the ones from the FoxPro file connection subroutine. 2.3. Opening an external table It is always more convenient to create a link to a table instead of opening an external table. This is due to the supplementary performance of the link method, and also due to the fact that it is very easy to use a linked table. After you created a link with a table, you can treat it as any other Access table. 217 Papers of the Sibiu Alma Mater University Conference, Fifth Edition, 24–26 March 2011, Sibiu – Volume 1 However there are some cases that require you to open an external table without creating a link. For opening an external table you must follow two steps: a) Opening the database using the OpenDatabase method. b) Creating an Recordset type object based on the external table. Here is how this kind of program looks like: Sub OpenExternal(sDBName As String, sTableName As String) Dim db As Database Dim rs As Recordset Set db = DBEngine.Workspace(0).OpenDatabase(sDBNam e) Set rs = db.OpenRecordset(sTableName) Do While Not rs.EOF Msgbox rs.Field (0).Value rs.MoveNext Loop End Sub Call OpenExternal (“C:\access\facturi.mdb”,”Facturi”) – In Access, views are called queries. As for SQL Server, one can create queries that can be modified, select lines from a query and create associations between several tables which are represented as queries – In SQL Server, columns represent data elements from a line. Although the term ‘line’ keeps its meaning in Access, the columns are called fields – The data types don’t have the same name and, in many cases, they physically differ when talking about SQL Server and Access. There are also other differences, but these are the main differences that may come in handy when using SQL Server together with Access. If you have an Access application, this is composed of up to six different elements. A short explanation of these elements is presented next, the extent to which these elements will be exposed to migration or conversion to SQL Server also being presented. 2.5. Tables You can see that in this case you don’t add a table definition. Instead of adding a table definition, you create a temporary Recordset which refers to the external data. After opening the external table as a Recordset, you will go through every record of the table, with displaying the value from the first field. Once you’ve opened the Recordset you can use it as you wish. 2.4. Using Microsoft Access together with SQL Server Microsoft Access represents an excellent development environment, with many of the SQL Server facilities available for testing and planning the implementation. Due to the fact that Access is a more reduced engine and because it has no real client/server operation, its use as a server system in a larger implementation is limited. However, it still remains an unique development environment when talking about database handling. Access provides a good user interface for developing tables and relations. There is a series of differences in the way that Access handles databases, including the issue of physical storage, and the specific terminology is slightly different. Here are a few examples: Similar to SQL Server. This is probably the the most important element that will experience migration. Tables in Access contain the lines of information that will be converted to SQL Server. 2.6. Queries Queries will probably require a conversion, which will have to be done mostly manually. So the SQL code which is behind every query will have to be examined and the corresponding SQL Server views will be created. Let’s also keep in mind that a connection to a SQL Server view can be created and used in a similar way to a table. 2.7. Forms Forms are not converted to SQL Server. Let’s recall that in the client/server model, the client system is in charge of handling the user interface and the server is in charge of maintaining and manipulating data. 2.8. Reports Like in the case of forms, reports aren’t usually converted. However, query based reports are different. In Access, a query can be created inside of a report. In order to obtain the best result, it is good to examine the properties catalogue of each report and to create SQL Server views based on the queries that were found. Then the queries from the report can be replaced by the new views. The 218 Ilie ŞUFANĂ - Interfacing possibilities in Microsoft Access, using external data sources and VBA code sequences performance will be better, the reports will act as if the query is created inside of them, but the effective result is a client/server implementation of the report. 2.9. Macrocommands Macrcommands are elements that are exclusively specific to the Access environment. It is possible that the macrocommands could call queries or execute commands at a higher level, so that an examination could be in order. Like in the case of reports, it is not recommended to use query based macrocommands, because these queries can be placed in SQL Server with a better performance. sub-routine has to be examined in order to determine how the migration should be done. In the case of modules, we have several options. We can transform a sub-routine in a stored procedure, in a view or in a dynamic query. This all depends on the processing that is done inside the database. The modifications will be done in short sequences, while continuously testing. It is very important to rigorously check the changes that were made before going to the next conversion, because the basic functionality of the system is involved. References 2.10. Modules Viescas J.L. 1999. Totul despre Microsoft Access 97, Editura Teora, Bucureşti. Modules can be rarely automatically exposed to migration. This means that each procedure and Morgan B. & Perkins J. 1997. SQL fără profesor în 14 zile, Editura Teora, Bucureşti. 219