I have created telephone directory in MS ACCESS called phone.mdb ...it contains the following
Title
Name1
Name2
Position
Dept
Floor
Phone
Fax
I would appreciate if someone help me writing the code to open this Database file using VB..
Printable View
I have created telephone directory in MS ACCESS called phone.mdb ...it contains the following
Title
Name1
Name2
Position
Dept
Floor
Phone
Fax
I would appreciate if someone help me writing the code to open this Database file using VB..
We now have a few tutorial threads at the top of each section, eg: in database development)
In there is a link which may be useful:
http://www.vbforums.com/showthread.php?threadid=153935
You need to be more specific,
Holly;)
VB Code:
Dim rstPhoneBook as Recordset Dim dbPhoneBook as Database Set dbPhoneBook= OpenDatabase(App.Path + "\phonebook.mdb") Set rstPhoneBook = dbLogin.OpenRecordset("TableName", adOpenDynamic) With rstLogin .OpenRecordset 'Do your things here End With
This is basic:NOTE:Code:Option Explicit
Private WithEvents conPhone As ADODB.Connection
Private WithEvents rsDir As ADODB.Recordset
Private Sub Form_Load()
Set conPhone = New ADODB.Connection
Set conDir = New ADODB.Recordset
Cn.CursorLocation = adUseClient
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= " & App.Path & "Phone.mdb"
With rsDir
.Open "Select * FROM Directory", conPhone, adOpenStatic, adLockOptimistic
If .RecordCount > 0 Then
txtTitle = !Title & ""
txtName1 = !Name1 & ""
txtName2 = !Name2 & ""
txtPos = !Position & ""
txtDept = !Dept & ""
txtfloor = !Floor & ""
txtPhone = !Phone & ""
txtFax = !Fax & ""
End If
.Close
End With
End Sub
It would be wise to include a Key in all tables.
e.g. EmployeeCode, a numeric field that increments when you wish to add an employee.