473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to connect the access database to visual basic 6.0

hi, i'm new in vb, so, please tell me how to connect access database in vb 6.0
Mar 31 '11 #1

✓ answered by VijaySofist

Hi raju selvam,

First you need to add a Reference named "Microsoft DAO 3.6 Object Library" to your VB6 Project

Then use the Following lines of Code

Expand|Select|Wrap|Line Numbers
  1. 'Declaration Section
  2. Dim db as Database
  3. Dim rs as Recordset
  4.  
  5. 'Form Load Event
  6. Set db=OpenDatabase(<<Your MsAccess Filename with path in Double Quotes>>)
  7. 'Example
  8. '-------
  9. 'Set db=OpenDatabase("d:\Vijay\Test.mdb")
  10. Set rs= db.OpenRecordset(<<Your MsAccess Table Name in double quotes>>)
  11. 'Example
  12. '-------
  13. 'Set rs= db.OpenRecordset("MyTable")
  14.  
  15. 'To Read from table
  16.  
  17. If (rs.RecordCount > 0) Then
  18. rs.MoveFirst
  19. Do While rs.EOF=False
  20. MsgBox (rs.Fields("FieldName").Value)
  21. rs.MoveNext
  22. Loop
  23. End If

You Can download a Sample from the link given below
http://www.vb6.us/tutorials/using-da...-code-tutorial

All the Best
Regards
Vijay.R

1 13010
VijaySofist
107 100+
Hi raju selvam,

First you need to add a Reference named "Microsoft DAO 3.6 Object Library" to your VB6 Project

Then use the Following lines of Code

Expand|Select|Wrap|Line Numbers
  1. 'Declaration Section
  2. Dim db as Database
  3. Dim rs as Recordset
  4.  
  5. 'Form Load Event
  6. Set db=OpenDatabase(<<Your MsAccess Filename with path in Double Quotes>>)
  7. 'Example
  8. '-------
  9. 'Set db=OpenDatabase("d:\Vijay\Test.mdb")
  10. Set rs= db.OpenRecordset(<<Your MsAccess Table Name in double quotes>>)
  11. 'Example
  12. '-------
  13. 'Set rs= db.OpenRecordset("MyTable")
  14.  
  15. 'To Read from table
  16.  
  17. If (rs.RecordCount > 0) Then
  18. rs.MoveFirst
  19. Do While rs.EOF=False
  20. MsgBox (rs.Fields("FieldName").Value)
  21. rs.MoveNext
  22. Loop
  23. End If

You Can download a Sample from the link given below
http://www.vb6.us/tutorials/using-da...-code-tutorial

All the Best
Regards
Vijay.R
Mar 31 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ray | last post by:
Date problem. Using non American date formats with Microsoft Access and Visual Basic. I set my regional settings to English(Ireland) or English(United Kingdom) and my date appears in Access as...
7
by: vigneshwaran G via DotNetMonster.com | last post by:
Hi , I am trying ot connect a VB application to Access database. iam using the following connection string : con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\...
3
by: kumarg | last post by:
how to create database in Ms-Access & how to connect that database with Visual Basic-6.0? Kindly let me know in detail.
2
by: czi02 | last post by:
does anybody knows how to connect access to visual basic?? I know that this is for access and database but hope that there is someone who could help me just a simple code on how to connect easch...
0
by: asad56 | last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
0
by: vacuit | last post by:
Visual Basic 2005 I want to save a copy of a datatable (that the user has changed) with a new name back to the database (Access) I have this code to save a copy with a new name to the...
6
by: Sicelo | last post by:
can you please help i am trying to convert access to visual basic with the forms and the code as a Data base?? or with the reports
0
by: sookfuny1984 | last post by:
In mysql, there is a query like select columnname, count(columnname) from tablename group by columnname If I wan to use Microsoft Access in Visual Basic 6.0 to do the same thing, how am I going...
2
9815402440
by: 9815402440 | last post by:
hi i want to connect access database which is on remote server (web server). can anybody please tell how to do this? thanx in advance. manpreet singh dhillon hoshiarpur
2
by: prasri | last post by:
Hi frends, I am newely joined in a small software company.I have bit knowledge in visual basic but i dont know connection strings and all.Can any one help me to give connection from Ms access to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.