How to connect the VB6 with MS Access 2003?
I am beginner in the programming language world(i.e beginner programmer). I am learning language: Core Java, Visual Basic, SQL, ASP and C sharp. In this days, i am doing project in Visual Basic 6 and this project has backend as MS Access. When i was trying to connect both i.e VB6 and MS Access 2003, i got error when i tried to connect between "record source" in VB6 with data that is saved Access. Please tell me how to connect the VB6 project with MS Access 2003.
Re: How to connect the VB6 with MS Access 2003?
As per my knowledge the Visual Basic 6 is only able to manage the MS Access 97 file formats. So, before connecting the MS Access 2003 file to the VB 6, convert the that Access 2003 file to the Access 97 format, because it supports only the Access 97 files. This converting can be done easily, Goto MS Access 2003-- Open your database file--Tools--Database Utilities--Convert Database --To Access 97 file Format. Once this is done you will not able to do any modification in your file so, take this after completing the modification or create a new access 97 file every time you make changes.
Re: How to connect the VB6 with MS Access 2003?
To connect Visual Basic 6 to the Ms Access 2003 file, you need to use the DAO or ADO as connection provider to the database. For this, inside Menu, put a click on Microsoft ActiveX Data Objects.
And in your project General Declaration Area, have to write this code:
Dim con As New ADODB.Connection
Dim r1 As New ADODB.Recordset
And in Form's Activate Event
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="your database complete path";Persist Security Info=False"
con.Open
r1.Open " select * from (your database name)", con, adOpenStatic, adLockPessimistic
Hope you will able to understand this code, and can apply in your project.
Re: How to connect the VB6 with MS Access 2003?
I would prefer to use the ADO(ActiveX Data Object) to connect VB6 to MS Access file. The ADO is the most basic and simple way to connect to the database. Basic of the connection is as follow:
Dim con As ADODB.Connection, recsource As ADODB.Recordset
Dim strCon as String, str1Sql as String
Set con = New ADODB.Connection
Set recsource = New ADODB.Recordset
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;"& "Persist Security Info=False;"&"Data Source=\\Server\Share\DatabaseName.MDB"
con.Open strCon
str1Sql = "SELECT * FROM Tablename "
recsource.Open str1Sql, con, adOpenKeyset, adLockOptimistic
Hope this code will make you understand how to connect MS Access.
Re: How to connect the VB6 with MS Access 2003?
I know one of the step to connect the Visual Basic to the MS Access2003, and it goes like this:Goto "Control Panel"--Click on "Performances and Maintenance"--Click on the Administrative tools option--DoubleClick on Data Sources (ODBC)--Note that you watch a dialog box--in that Click System dsn--After that Click on add-- Again DoubleClick Access2003 driver .mdb--Click Select then find the Access2003 database which you saved--then click on OK--In the Data Source Name option type the filename of the Ms Access Database( like db1.mdb)--Click OK. Press enter. Hope this method will allow to use the MS Access2003 files in Visual Basic 6.
Re: How to connect the VB6 with MS Access 2003?
According to me you should use either the ADO(ActiveX Data Object) or DAO(Data Access Object). This are the basic and most simple method used to connect VB 6 to the MS Access. The basic code for ADO is as follow:
In general declaration
Dim con as Adodb.connection, rs as Adodb.recordset
Dim sql1 as String, sql2 as String
Private Function Connection()
Set rs = New ADODB.Recordset
Set con = New ADODB.Connection
sql1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" Fullpath of database" & ";Persist Security Info=False"
con.Open (sql1), , , 0
End Function
Call this Connection in which ever form you want the database connection.
Hope you will get solve soon and your project gets complete on time.