hope all of you guy's like this tutorial it's simple and easy way to access microsoft access database in vb using ado code library
here we go
'code start here define veriable for connection and recordset
'the variable code end here
'code for form_load
'code end here
'now add code for cmd first
'thats it it will just show record from fields to text boxes the text boxes name is
text1
text2
text3
text4
and database fields name are
productname
productprice
totalamount
amountbalance
tabel name is tbhome that's it if anyone have any quistion then ask me
likehamza@yahoo.co.uk
here we go
'code start here define veriable for connection and recordset
| Code: |
| Dim db As New ADODB.Connection
Dim tb As New ADODB.Recordset |
'the variable code end here
'code for form_load
| Code: |
| Private Sub Form_Load()
tb.CursorType = adOpenDynamic ' if database is password protected then use the string given below 'db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\Database\h1.mdb;Jet OLEDB:Database Password=hamza;" '"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\dbhome.mdb;Persist Security Info=False" 'if database is not password protected then use the string given below db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database\h1.mdb;Persist Security Info=False" tb.Open "select * from tbhome", db Text1.Text = tb("productname") Text2.Text = tb("productprice") Text3.Text = tb("totalamount") Text4.Text = tb("amountbalance") End Sub |
'code end here
'now add code for cmd first
| Code: |
| Private Sub cmdFirst_Click()
tb.MoveFirst Text1.Text = tb("productname") Text2.Text = tb("productprice") Text3.Text = tb("totalamount") Text4.Text = tb("amountbalance") End Sub 'code for cmdlast Private Sub cmdLast_Click() tb.MoveLast Text1.Text = tb("productname") Text2.Text = tb("productprice") Text3.Text = tb("totalamount") Text4.Text = tb("amountbalance") End Sub 'code for cmdper Private Sub cmdPrevious_Click() If Not tb.BOF Then tb.MovePrevious If tb.BOF Then MsgBox "FIRST RECORD" If tb.BOF Then tb.MoveFirst Text1.Text = tb("productname") Text2.Text = tb("productprice") Text3.Text = tb("totalamount") Text4.Text = tb("amountbalance") End Sub 'code for cmd next Private Sub cmdNext_Click() If Not tb.EOF Then tb.MoveNext If tb.EOF Then MsgBox "LAST RECORD" If tb.EOF Then tb.MoveLast Text1.Text = tb("productname") Text2.Text = tb("productprice") Text3.Text = tb("totalamount") Text4.Text = tb("amountbalance") End Sub |
'thats it it will just show record from fields to text boxes the text boxes name is
text1
text2
text3
text4
and database fields name are
productname
productprice
totalamount
amountbalance
tabel name is tbhome that's it if anyone have any quistion then ask me
likehamza@yahoo.co.uk
