Results 1 to 5 of 5

Thread: Open DataBase created in MS Access?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    237

    Open DataBase created in MS Access?

    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..

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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

  3. #3
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    You need to be more specific,

    Holly

  4. #4
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    VB Code:
    1. Dim rstPhoneBook as Recordset
    2. Dim dbPhoneBook as Database
    3. Set dbPhoneBook= OpenDatabase(App.Path + "\phonebook.mdb")
    4. Set rstPhoneBook = dbLogin.OpenRecordset("TableName", adOpenDynamic)
    5. With rstLogin
    6.     .OpenRecordset
    7.  
    8. 'Do your things here
    9. End With
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  5. #5
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    This is basic:
    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
    NOTE:
    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.
    Mel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width