Database Guide


This Visual Basic 6 guide walks you step by step through VB6 tutorials and VB6 source code on this site that will help you learn how to develop applications that store and retrieve data from database back ends. As you read each of these database tutorials you will gain more and more knowledge in how to handle databases in your VB apps. The best way to navigate through the guide is by using the links on the left. Or you can use the links below and then hit your browser's back button. Each link will take you to a different vb6 database tutorial on this site that will teach you the next step you need in order to become a VB6 database guru.

  1. To do anything of value in Visual Basic related to databases you will first need to learn how to write SQL statements to extract what you want from your back end database. This applies to not only Microsoft SQL server but also to Access and Oracle databases. Learn how with this Introduction to SQL (Structured Query Language)
  2. The data control in VB6 allows you to interact with your backend database with out having to write all the code by hand. This is great when you are first learning how to do database development in Visual Basic or for quick and simple VB6 database applications. For more complicated applications you will probably use ADO. Still check out this Database Access with the VB6 Data Control tutorial to start getting your feet wet.
  3. This tutorial is optional as DAO is a somewhat older way of Visual Basic database development. However, if you ever have to interact with older code its good to at least understand the basics of this. Check out the Using DAO (Data Access Objects) Code Tutorial
  4. Again, RDO is still not the newest (and best) way to access back end data. However, there is a lot of VB database code out there that uses RDO so its probably good to at least glance through this tutorial in order to know what to do if you ever work on and VB RDO project. Database Access with RDO (Remote Data Objects) in VB6
  5. This is a must read! Visual Basic ADO development is the newest (and best) way to interact with any database. After walking through this tutorial you should be able to have every tool in your belt to grab data, modify it, and write back to any database you come in contact with. Any VB6 database developer must read this Database Access With ADO in VB6 tutorial
  6. Once you understand all the basics of how to use ADO to work with a database you will probably want to display that data to your end user in some way. One very effective way of doing this is with the list view that is built into the VB6 IDE. Using ADO and the ListView control in VB6
  7. It is bad programming practices to write all your SQL statments directly into your Visual Basic source code. This makes it hard to change things down the road and also has a performance disadvantage compared to using stored procedures. Learn how all this works in this tutorial: Using ADO and stored procedures in VB6
  8. If you ever need to print of reports for end users you might want to consider using Crystal Reports. Although many times you can get away with writing your own reports or exporting things to Excel or Word at times this isn't an option. Check out this Using Crystal Reports with VB6 tutorial to learn more about how to create these for your end users.
  9. Optional: This is optional because unless you are having to interact with an Oracle database you will never need to know this information. However if there is a time you need to use Visual Basic and Oracle together I recommend you check out this
  10. If you enjoyed this post, subscribe for updates (it's free)

payroll System and library system

Hi,Good Day,
Can i have favor to? We have final requirements and we need to do a payroll system using vb6.0 how can i have a code for this,pls help me,,
i will wait for your answer,this is my email
I do appreciate your help.thank you very much.:)

Badly in need of HELP

hi guys
i have an ACCESS database uploaded on the internet and i wanna connect to it via VB6.
any one has any idea about how to do such chore?

Online database

I don't think you can connect to online databases, but one thing is sure- you can always download it and use.


Help on vb database project

please Sir i need a code that will help to connect my project to a database using Ms access and i also want the saved records to be display on the the data Grid and i don't know how to carry out the work or assignment. please i would like you to reply to my problems as quickly as possible through my email contact Thanks.

Connecting vb6.0 to ms access database

Don wallace: this is my first post on this site and i'm very sure that this will work if you follow the steps properly. Load vb6.0 and click on standard exe then open when the dialogbox displays. Press ctrl+T and click on the check box behind microsoft ado data control 6.0(oledb) and also click on microsoft datagrid control 6.0(oledb) then click on ok and these controls will be added to the toolbox. Add these two controls to your form, click on the ado control and click on commandtype frm d properties window and change the type to adcmdtable, click on connection string and click on d "...", then click on build when d dialogbox appears, select microsoft jet 4.0 oledb provider and click next, at d select db name, click on d "..." and locate ur db name. When found, click on open. Click on test connection, if a successful msg pop out, dat means ur connection was ryt. Click on ok, click apply, den ok. Frm d properties window, locate recordsource and click on d "...", select d tbl name and click on apply den ok. Click on d datagrid control, frm d properties window, click on datasource and change it to adodc1, right click on d datagrid control and click on retrieve fields and click yes when a msgbox appear. (connection has been completed). To add new records, add dis codes to d code window: sub add() 'dis code add 'new records to db. 'press enter 'frm d keyboard and type dis code. Adodc1.recordset.addnew 'press enter sub save() 'dis code save 'new records to db. 'press enter 'frm d keyboard and type dis code. Adodc1.recordset.update 'press enter sub deleteIt() 'dis code delete records from db. 'press enter 'frm d keyboard and type dis code. Adodc1.recordset.delete adaffectcurrent 'press enter

i have a access database.i

i have a access database.i want to get records of that database from vb6.i mean as example when i type 14dp in textbox and hit enter i want to obtain the records related to 14dp and can i do it? do i want to use indexing?

Reply to comment (VB6)

Hello there, just became alert to your blog through Google, and found that it's really informative. I am going to watch out for brussels. I'll be grateful
if you continue this in future. Many people will be benefited from your writing.


0 or empty
0 or empty
total is: 3 it will not count the 0
what is the code for this i am using vb 6 with dbms

please help


hallo sir how are name is deepak. I am making a project for my city and for study project name is CManager(CLASS MANAGER). Software completed 80%. I have some littile problems in vb6. Sir i want to take your help............thankyou

Payroll - Search then Print the Data from DataGrid.

Help! I badly need the code for Search from Employee No then Print the Result into Datagrid.

Thanks :)

Searching using TextBox and Display on the DataGrid

Hi please help.

I am looking for a source code that will only displayed an item that I enter on the text box into a data grid.

I am using ms sql 2008 database, and vb 6.0

Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset

con.CursorLocation = adUseClient
rs.CursorLocation = adUseClient

con.Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=vbDatabase;Data Source=matrajex-PC\SQLEXPRESS")

If rs.State = 1 Then rs.Close
rs.Open "Select *from BasicInfo", con, adOpenDynamic, adLockBatchOptimistic
Set Me.DataGrid1.DataSource = rs

this code above for the connectin and displaying items on data grid

please send me a code for the searching engine using textbox and diplaying it to data grid.

thank you in advance..

About Image..

I am doing one project in vb 6.0 name is agricultural college system.
which include all information about student from he/she admitted to leave college.
like.. filling registraion form,grade system,balance sheet,reports etc.

sir is there any code to attach student image on the registration form/report.

& how to connect different report using 1 code (Ex. firstyear..2012.2013.2014.. etc. )

Plz. send me info. at


Please i could you help me a code, how to export vb6.0 report to excel

Please could you help me a

This is a great vb6 database tutorial but please could you help me a code, how to export vb6.0 report to excel

search between two dates


Please I need help to search between two dates and take record between two dates

help for vb 6.0

i have simple vb form(not MDi form) ...
I'm try to create a list of menu when I'm select vsflexgrid create a menu.........???

Hi Sir

Sir.. can you pls send me codes on how to print a specific data in the database using vb6.0? thank you.. God bless :)


use datareport fro print your data u want to print :D

ConnectionDB = path of your database

rs = recordset
db= connection


rs.Open "select * from tblPersonalInformation where ID like '" & ListView1.SelectedItem & "'", DB, 3, 3
If rs.RecordCount <> 0 Then
With DataReport1
Set .DataSource = rs

.Sections("section1").Controls("Text1").DataField = ("Lastname") // only lastname of thespecific id will be print

End With

MsgBox "No Existing Record Found", vbExclamation + vbOKOnly, ""

Exit Sub
End If

DataReport1.Show 1

that's all ehehe :D

Syntax Error

strsql = "insert into tblinfo(ID, Name, Age, Gender, Birthday, Address, Contact_Number, Citizenship, Religion, Guardian, Level, Type_of_Student, Transferee, Last_School_Attended, Date_Enrolled)values(" & Me.txtid.Text & ",'" & Me.txtname.Text & "'," & Me.txtage.Text & ",'" & Me.cmbgender.Text & "',#" & Me.dtpbirth.Value & "#,'" & Me.txtaddress.Text & "'," & Me.txtcontact.Text & ",'" & Me.txtcitizen.Text & "','" & Me.txtreligion.Text & "','" & Me.txtguardian.Text & "','" & Me.cmblevel.Text & "','" & Me.cmbts.Text & "','" & Me.cmbtransfer.Text & "','" & Me.txtsla.Text & "',#" & Me.lbldate.Caption & "#)"



code solved

strsql = "insert into tblinfo(ID, Name, Age, Gender, Birthday, Address, Contact_Number, Citizenship, Religion, Guardian, Level, Type_of_Student, Transferee, Last_School_Attended, Date_Enrolled)values(" & Me.txtid.Text & ",'" & Me.txtname.Text & "'," & Me.txtage.Text & ",'" & Me.cmbgender.Text & "',#" & Me.dtpbirth.Value & "#,'" & Me.txtaddress.Text & "'," & Me.txtcontact.Text & ",'" & Me.txtcitizen.Text & "','" & Me.txtreligion.Text & "','" & Me.txtguardian.Text & "','" & Me.cmblevel.Text & "','" & Me.cmbts.Text & "','" & Me.cmbtransfer.Text & "','" & Me.txtsla.Text & "',#" & Me.lbldate.Caption & "#)",con

Please write connection.

how to connect

how to connect the system in the database (My SQL 2008)
it is easy to use or it has an complication using it to connect in the vb6 system:>



Just to clarify are using MS SQL Server 2008 or MySQL?

Best regards,


How to coonect VB using conection string

Hi my fellows
I know To connect VB and Access using Adodc, Now I want to change that to connect VB with Access using connection String. Can you help me steps of this connection.
Help me please.

global declaration

Hi sir,
I have a field named Transaction number in my db which is an auto number. The Transaction number field has a one to many relationship with other tables in my database. I have already connect my database with vb. I have a master form that has a textbox 'Transaction number' and the button save. I would like it to be such that when i click 'save' button another child form appears with adodc property set to add edit mode and the Transaction number from the master form to appear in a textbox in the child form so that i can be able to save without messing up with referential intergrity in my db,
please help.

Can Someone Please help me?!?!?

I have a table and I connect it in VB6.0 through adodc and datagrid. I want to get the value of the last entry in field named "BOOK NUMBER" into texbox. See this for more info

please help me

Hi Friends,
I develop one application project in visual basic. I don't know how to develop the code. please help me.
Thank you

what kind of app. you trying

what kind of app. you trying to develop?

I would like to keep employee

I would like to keep employee and office equipmet mgt records

please tell

please tell


I need to develop a program with a database and to which you can add data in excel sheets to the database from a thumb drive. Please help.

How to retrieve data using string

if you can retrieve data in a textbox like this

Set txtUsername.DataSource = rs 'where rs = ADODB.Recordset
txtID.DataField = "Username"

how can i retrieve data without any control? just using strings?

Search in Datagrid(vb 6.0)

Please!! Give a code of search in datagrid in vb 6.0
when you click search the ID and the info will appear in datagrid

All I know is when using

All I know is when using ADODC in connecting MS access put the adODC in the form with ur data grid connect it. In ur data grid property Recordsource the table that u want to appear in your datagrid will be there u just have to select it. and then right click ur data grid and select retrieve fields. So that the table in ur database will appear in the datagrid. LAst thing is putting the code Sample:

adoloan.recordsource=" Select * from qrybookloan where stud_ID= '" & txtsearch.text & "'"

Set Datagrid.datasource.Update

Hope it helps u.

Exporting to Excel


..need some help..

How can i export my data from access to Excel using ADO data control?


send me a code that will

send me a code that will allow me to save and print from ms excel

hello Sir;

hi sir can you help in doing my project a enrollment system that can add, search,edit,delete or archiving..bless.
hope you can help me sir..thank you god bless:-)

hi which kind of help do you

which kind of help do you need you can add , delete or search a record please send me a project information which kind of database you use access , sql etc

Login That will apear to datagrid

To All Concerned Programmer,
Please help me to do this job username and password that will apear in my Datbagrid ...
tnx!! i dont know how to work with module...
please e-mail me @

Government Election System

Please help creating a client server program that can be used in voting in our school..
The Server should be the one who can only be able to check the votes..
And the client should where they can vote using mysql.. Please.. help me.

Election System using MYSQL

Please contact me at my email address: and we will discuss the Elecction System

How to view oracle table data on vb6.0 data grid view

Please give me suggestion How to view oracle table data on vb6.0 data grid view. I need cordially help from you. I am trying but do not show accurately. So, please tell me what can I do for this situation. Thanks.

how can i set the print a specific record from access with vb

respecter sir

i want to know the set the print options

export many book excel for visual basic

Hello, hola, quiero exportar a muchos libros de excel, este codigo solo exporta a un solo libro, pero si deseo que sea por segmento, ejemplo: por zona, oficina. si es por zona que exporte x libros de excel donde cada libro tendra informacion oficina, nombre cliente, etc

help me please.

iam have is code

Private Sub exportar_Datagrid(Datagrid As Datagrid, n_Filas As Long)

On Error GoTo Error_Handler
Dim ObjExcel As Object
Dim i As Integer
Dim j As Integer

Me.MousePointer = vbHourglass

If n_Filas = 0 Then
MsgBox "No hay datos para exportar a excel. Se ha indicado 0 en el parámetro Filas ":
Exit Sub
Set ObjExcel = CreateObject("Excel.Application")
ObjExcel.Sheets("Hoja1").Name = "Reporte Cartera"
' title
ObjExcel.ActiveSheet.Cells(1, 3) = "Report"
With ObjExcel.ActiveSheet.Cells(1, 3).Font
.Color = vbBlack
.Name = "arial"
.Size = 11
.Bold = True
End With

iCol = 0
For i = 0 To DataGrid1.Columns.Count - 1
If DataGrid1.Columns(i).Visible Then
iCol = iCol + 1
ObjExcel.ActiveSheet.Cells(4, iCol) = DataGrid1.Columns(i).Caption
For j = 3 To n_Filas - 1
ObjExcel.ActiveSheet.Cells(j + 2, iCol) = _
End If

ObjExcel.Visible = True
ObjExcel.SheetsInNewWorkbook = 1

End If
Set ObjExcel = Nothing
Me.MousePointer = vbDefault

Exit Sub

' -- Error

MsgBox Err.Description, vbCritical
On Error Resume Next

End Sub

Request for help

how do i connect a table to individual record in the database. am using Adodc as my data control,

need help

Hi,, Master VB

I need help,, I create RFID for parking system,, I used Ms. access 2003 ,,, my database with VB is already connect using ADODC,,

MY PROBLEM IS ,,, how to display the image on VB,,

thanks,, cant wait for response

New in VBA from VFP6

I often confuse with vb codes. As VFP, a subroutine is always inactive whenever its called or a related object is excited. My program as follows in VBA:-

Dim conn As ADODB.Connection
Dim mytbl As ADODB.Recordset
Dim strsql As String
Dim cmd As ADODB.Command

Private Sub cbo1_Click()
wrong codes
End Sub

Private Sub Form_Load()
strsql = "cusp"
Call link2db
txtnm.Text = ""
End Sub

Private Sub link2db()
Set conn = New ADODB.Connection
Set mytbl = New ADODB.Recordset
conn.Provider = "Microsoft.jet.oledb.4.0"
conn.Open App.Path & "\busi97.mdb "
Call actcbo1
End Sub

Private Sub actcbo1()
mytbl.Open strsql, conn, adOpenDynamic, adLockPessimistic
x = mytbl.Fields(0)
cbo1.AddItem ("No Data Found")
If x = 0 Then
cbo1.Enabled = False
Do While Not mytbl.EOF
cbo1.AddItem (mytbl.Fields("names"))
cbo1.Enabled = True
End If
cbo1.ListIndex = 0
End Sub

'When I run this form, it is giving error in cbo1_Click subroutine, since its not clicked.
'Thanks as advance.

Delete row DATAGRID

How i add a button in each row in a DataGrid? Or how I do to delete a selected row when i click them?


Pls tel me how pass a value to parameter using vb 6.0 to excel
Dim strGarage As String
rsRec As New Recordset

With conn
.CursorLocation = adUseClient
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & App.Path & "\a updated garageCheckoutScanningCompliance 9-1 through 9-9-22.xlsx;" & "Extended Properties=""Excel 8.0;HDR=Yes;"";"
'.ConnectionString = "Data Source=" & App.Path & "\Book1.xlsx;" & "Extended Properties=Excel 12.0;" "Extended Properties=""Excel 8.0;HDR=Yes;"";"
End With

rs.Open "Select * from [garageCheckoutScanningComplianc$A1:A68] ", conn, adOpenDynamic, adLockBatchOptimistic

when I open the record set how cn I use the Where clause to select the peticuler cell in Excell


Good day Sir,

I want to ask for a help regarding my database project, I'm using vb6 ang MySql database. How can I save a data from one table to another table in database using a datagrid of vb6? Can you give me some codes regarding on that problem?

Thank you! God Bless!

computer programming

help me to make my data base...please give me some codes..........tanx....

going bck to the basics

please help me i need to create a database where i can capture clients name for a company where they can enter the following details:
Full names
Identity Number
Telephone Number
using vb 6.0

Creating database using Vb6

Firstly, Create a database using below any of the two methods below,
There is one way of creating database using visual data manager in the Add Ins of visual basic 6.0 menus.

Another method Create a table using Microsoft Access and convert to access 97 using convert utility using access.

Now create a form in vb as to capture to datas of clients and using add and update buttons using database.
Then code to add and save, for any further real code send complete requirements of ur project.
and contact me through mail.



My e-mail is:

Send me a message there or add me at MSN or Yahoo messenger so I can help you from there.

Looking forward for your reply.



this website is very helpful:)

i have many problems about

i have many problems about database,, can you please help me..


Send me your problems at in order to discuss them.

See you then.


how to create a table in oracle database from vb

how to create a table in oracle database from vb


i am trying to write a code for a Visio file (with more than 1 flowsheets) to SAVE AS .jpg files for all flowsheets

Public Sub JPGCon()

Dim FS As String
Dim i As Integer
Dim vsoPages As Visio.Pages

Set vsoPages = ActiveDocument.Pages

For i = 1 To vsoPages.Count
FS = vsoPages.Item(intCounter).Name 'get the page name and assign to FS
Application.ActiveWindow.Page.Export (FS.jpg) 'assign the SAVE AS file with the FS name and extension as .jpg

Next i
End Sub

but somehow this code do not work and shows error at - Application.ActiveWindow.Page.Export (FS.jpg) .
I want to keep the variable name to .jpg to be created.
can anybody help me on this...

vb project not load on other pc

in my project use adodc connection with database file students.accdb
give me solution for that problem

Does the "other pc" has

Does the "other pc" has Access 2007 installed!?
.accd file format is exclusive for 2007 office package.

Radio Button in VB6.0

Hi all

I am new to VB6.0, can any one tell me the sample code to insert Radio Button (Yes / NO value) to MS Ascess Database

Please someon help me

Im programming for household book. I need to design log in form. In log in form I can't get what i should type for it.

Im not using Im just using MDB 7.0 and VB6

I have a register form which enables customer to register his/her Id and password

and in log in form it should check with database and decide log in - succed or fail.

And im coding date search i dont know how to do help me please


How can i add in database withou a duplicate record using vb6 and ms access..thanks

table fields dispaly in combobox(Database)

pls help me..

i want to access my table fields after adding it from combobox and display in combobox with the same name....

thank you,...


My e-mail and MSN is:


HELP.. high school enrollment system

i need help in making high school enrollment system using vb 6.0. please help me.. i need codes.. Enrollment system that can, add, edit, delete, view, search and print... i need it as soon as possible.. thanks so much

DataGrid in VB6/SQL Server

I am using msflexgrid in VB6/SQL server. I want to change msflexgrid to datagrid. Can some one mail me a sample programme using datagrid with vb6/sql server. Thanx in advance

vb6 & combo box

how can i put all the names in my access field in a combobox in vb6?


SET Recordset = Connection.Execute("SELECT * FROM MyTable")

While not Recordset.EOF
Combo1.AddItem Recordset!MyField

Combo1.ListIndex = 0 'The first item of the combo box will be displayed

How to connect Access Database with VB

If any body can help to learn the following.
I have good knowledge of Microsoft Access and can write
VB code. I have written VB functions also. Have made Access application too.

1. How to connect Access Database with Visual Basic
2. How to make complete VB project and EXE apps