answersLogoWhite

0

There are plenty of ways you can do this. The 2 most common would be a Data Control, which will give you a record navigator just like in access, you can bind this to a Data Bound List, Grid or Combo Box to display it.

The other way would be to use ADO directly in VB code. Both are pretty similar, and theres only a couple of steps to connect it all up.

To use the Data control, First Create a new VB6 project and goto the Project -> Components menu. In here check the item "Microsoft Data Bound Grid Control 5.0" and click OK.

Now you can drag out both the "Data" control, and the "Data Bound Grid". On your new Data1 control, you can set the path to your access database and what table or query you want to use. Then you can select your DBGrid1 control and set it's "Data Source" to "Data1".

This is fine for something basic, but anything more advanced you're going to want to use code.

First step, go to www.connectionstrings.com and make a connection string for your database. This is where you select what type of database you're using (in this case, Access), and where you set your database password, file location and advanced options.

Now, Create a new VB6 project and goto the Project -> References menu. In here find and check the "Microsoft ActiveX Data Objects 2.6" library.

Now double click on the form to get to the Form_Load event, and add the following.

Dim oCon as New ADODB.Connection

Dim oRs as New ADODB.Recordset

oCon.Open "Connection String"

oRs.Open "SELECT * FROM TABLE", oCon, adOpenKeyset, adLockOptimistic

Now you can use the data from the query "SELECT * FROM TABLE" in code. Use oRs!FieldName to access each field's value, and use the oRs.MoveNext, .MovePrevious, .MoveFirst & .MoveLast functions to navigate around.

Eg

' Connect to the database in the same folder as the application

oCon.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\Data.mdb;Uid=Admin;Pwd=;"

' Grab only the fields & data we need to work with.

oRs.Open "SELECT Name, Price, Views FROM Products WHERE Stock > 0", oCon, adOpenKeyset, adLockOptimistic

' Loop until we get to the end of the table

Do Until oRs.EOF

' $5.00 - Chips

List1.AddItem "$" & Format(oRs!Price, "###0.00") & " - " & oRs!Name

' Add 1 to this items "views" counter

oRs!Views = oRs!Views + 1

' Move to the next record

oRs.MoveNext ' Move to the next record

Loop

User Avatar

Emilia Smitham

Lvl 10
2y ago

What else can I help you with?

Related Questions

How do you connect to mysql using vb6?

Install the MyODBC database connector.Set up an new ODBC connection to your mysql database in Windows. (This will vary based on your version of Windows)You can use the ADODB extension in VB to connect to your ODBC connection.


How do you connect to a database using unix command?

There isn't a generic Unix command to connect to a database. The actual commands are based on the database package you are using, such as Oracle, SyBase, etc. They each have their own commands for gaining access to the database.


Is Access a database software application?

Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.Microsoft Access is a database.


How do load an access database over HTML?

A database cannot be accessed directly by HTML. You need jars and a language like Java to connect a DB.


How do you connect to a database and table using ADODB?

How do you connect to a database and table using ADODB?


How do you connect visual basic 6.0 access database using module and data environment?

There are several ways to connect Visual Basic 6.0 access databases, but to use module and data environment equipment, one must obtain access to the actual program to download first.


What is database in access?

An Access database is a relational database contained in a single file that you can upload to a directory on your Web server. People typically create an Access database file using Microsoft Access or FrontPage.


What is a database in access?

An Access database is a relational database contained in a single file that you can upload to a directory on your Web server. People typically create an Access database file using Microsoft Access or FrontPage.


How do I create a form which will then upload to a database that I can access in Microsoft Access?

Have your form's input insert into a database (SQL, Oracle, etc) then access that database through Access's ODBC connection.


What are the differences between Microsoft Access and database?

None. Microsoft Access is a database application.


How do I convert 2003 access database to 2007?

Open the database in Access 2007 and save as Access 2007 format.


Does database software store information in HTML codes?

No, database software does not store data using Hyper Text Markup Language (HTML) codes. A common code used to access data is Structured Query Language (SQL). HTML is a formatting language that will tell a browser how to display the data retrieved from a database.