This tutorial will only create a connection between visual basic and ms access. Note 2: You may wonder that the ms access database has no table, for now we don’t need tables, fields and records. Note 1: your vb project (.vbp), the executable file (.exe), the form (SplashFrm), the module (DBConnect) and the ms access database (Data.mdb) should be on the same directory or folder. The SplashFrm form will appear indicating that you have successfully established a connect to your ms access database. You are all set to run your project, press F5 to run the project.ġ5.
Sub Main is the name of the procedure in which we have placed the code that connects visual basic to ms access.ġ4. Project Properties dialog box will appear, in the Startup Object kindly select Sub Main. After you have inserted to code above, in the menu bar select Project and click Project1 Properties (Project1 may vary depending on the name of your visual basic project).ġ3. MsgBox "Error Opening " & MSDatabase & vbNewLine & Err.Description, vbCritical, "Can't establish a connection"ġ2. Public rs As New ADODB.RecordsetĬonString = "Provider=.4.0 User ID=admin Data Source=" & App.Path & "\Data.mdb Jet OLEDB:Database Password=" Open the Module that you have created (DBConnect) and paste the code below.
How to add Microsoft ActiveX Data Objects 2.8 Libraryġ1. References dialog box will appear, from the list of references, check the Microsoft ActiveX Data Objects 2.8 Library and click OK. To add the Microsoft ADO 2.8 library, in the menu bar select Project and select References.ġ0. Before we write the code that connects our visual basic program to ms access, we will first add the Microsoft ADO 2.8 library in our visual basic.ĩ. (you can choose any name you want for this module)Ĩ. In the project explorer, right click and add a Module. By default there is only one Form (Form1).ĥ. On the file menu, select New Project and select Standard Exe.Ĥ. Kindly open your visual basic 6 program.ģ.
Create an ms access database and save it as Data.mdbĢ. In this tutorial we need ms access database (2000-2003 format) (.mdb), a Visual basic form and a Moduleġ. Demo - COVID-19 Facilities Management Information System