Showing posts with label VB 6.0 Tutorial. Show all posts
Showing posts with label VB 6.0 Tutorial. Show all posts

VB 6.0 - Display data in database with combobox

8:12:00 PM 2
In this post we will share VB 6.0 about How to display data in database with combobox. Result of this tutorial when click data in combobox show or display data in database
Please following below :

1. Built database DB.accdb
We have DB.accdb with Table Customer :

2. Open your VB 6.0 application
Design form like below picture
VB 6.0 - Display data in database with combobox
Copy DB.accdb include folder where you crated project VB 6.0
Place below code in form1 :
Dim Conn As New ADODB.Connection
Dim RSCustomer As ADODB.Recordset
Sub FormEmpty()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Sub OpenDB()
    Set Conn = New ADODB.Connection
    Set RSCustomer = New ADODB.Recordset
    Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\DB.accdb"
End Sub
Private Sub Form_Activate()
 RSCustomer.Open "TBL_CUSTOMER", Conn
        Combo1.Clear
    Do Until RSCustomer.EOF
        Combo1.AddItem RSCustomer!Customer_id
        RSCustomer.MoveNext
    Loop
End Sub
Private Sub Form_Load()
FormEmpty
    Call OpenDB
    Adodc1.ConnectionString = Conn
    Adodc1.RecordSource = "TBL_CUSTOMER"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1
End Sub
Private Sub Combo1_Click()
    Call OpenDB
    RSCustomer.Open ("Select * From TBL_Customer where Customer_id='" & Combo1 & "'"), Conn
    If Not RSCustomer.EOF Then
        Text1 = RSCustomer!Name
        Text2 = RSCustomer!Address
        Text3 = RSCustomer!Phone
    End If
    Conn.Close
End Sub

and the last, please run your projec
You can click here to download project / source code above

VB 6.0 - Display data in ComboBox

6:18:00 PM 0
In this tutorial we will share about Display data in ComboBox using VB 6.0. You can practice with me.
Please design Form1 in VB 6.0 like below picture :
at Combo1, we will show or display data gender. you can place code below :
Private Sub Form_Load()
Combo1.Clear
Combo1.AddItem "Male"
Combo1.AddItem "Female"
End Sub

and then, Please run your project
Here the result :

You can click here to download project / source code above

VB 6.0 - Validating length text entered into text box

5:43:00 PM 0
In this tutorial, we will share about validating in VB 6.0. for this post we will share regarding Validating text entered into text box in VB 6.0

for the sample, please design like above picture
usually we already create table in database set length Product ID = 6 digits
so if we entered exceed than 6 digits is error (can not be add to database. so we must validate Length of Text
in above design form above we will validate text entered in Text1.
the code is very simple :
Sub Form_Load()
Text1.MaxLength = 6
End Sub
If you place the code and run your project. you just only entries at text1 just 6 digits
You can click here to download project / source code above

VB 6.0 - Validate only allow numeric

5:40:00 PM 0
In this tutorial we will share about  Validate only allow numeric in form VB 6.0

VB 6.0 - Validate only allow numeric
Please design like above picture.
In above picture, we will validate Text3 and text4 only allow numeric.
for validate only allow numeric you can add code below
Private Sub text3_KeyPress(KeyAscii As Integer)
    If Not IsNumeric(Text3.Text & Chr(KeyAscii)) And Not KeyAscii = 8 Then KeyAscii = 0
End Sub
Or you can use below code :
Private Sub Text3_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then KeyAscii = 0
End Sub
and the last you can run your project
You can click here to download project / source code above