Consulting

Results 1 to 5 of 5

Thread: Switch from Excel to Access

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Switch from Excel to Access

    I am currently using an excel file as a database for my add-in. What it does at different points in the add-in, it looks up information in the excel file and fills it into another Excel file. I want to change the database from an Excel file to an Access file but I have a few questions about it.

    1) Does it run quicker to get information from an Access file as opposed to an Excel file?

    2) Do I need to open up the access file to get information from it? or can I access the information with the file closed? I know you can get the information from an Excel file when it is closed but it runs much slower.

    Thank you,
    Daniel

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Using ADO it will be quick(ish) from Excel or an mdb file.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    ok thank you but do I need to open the Access database before extracting data from it?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not with ADO you don't.

    [vba]

    Sub GetData()
    Const adOpenForwardOnly As Long = 0
    Const adLockReadOnly As Long = 1
    Const adCmdText As Long = 1
    Dim oRS As Object
    Dim sConnect As String
    Dim sSQL As String
    Dim ary

    sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & "c:\bob.mdb"

    sSQL = "SELECT * From Contacts"
    Set oRS = CreateObject("ADODB.Recordset")
    oRS.Open sSQL, sConnect, adOpenForwardOnly, _
    adLockReadOnly, adCmdText

    ' Check to make sure we received data.
    If Not oRS.EOF Then
    ary = oRS.getrows
    MsgBox ary(0, 0) & " " & ary(1, 0) & ", " & ary(2, 0)
    Else
    MsgBox "No records returned.", vbCritical
    End If

    oRS.Close
    Set oRS = Nothing
    End Sub
    [/vba]

    It gets it from the disk file.
    Last edited by Bob Phillips; 01-07-2008 at 10:33 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Jun 2007
    Posts
    150
    Location
    I've been building a bunch of Apps lately that use an Excel front-end and a Access DB behind it... Its a powerful combination!

    The only problem with ADO is that if you are going to be rolling the finished app out to a large user base, its generally safer to use Late Binding. Xld's code above uses Late Binding.

    If you are new to ADO, here are a few simple examples of using ADO to fill a combo-box from an Access table:

    http://www.fontstuff.com/vba/vbatut10.htm



    Edit: Doh, I misunderstood your question.

    To clarify what Xld said: NO, you do not have to open Access or the MDB file, the ADO driver can access the DB inside the MDB file automatically, as long as you have file system access to the MDB file. (this means the MDB file can be on a shared drive, folder, server, etc etc)

    This means that the end users DO NOT need to install MS Access. If your app uses an Excel front end, the Access DB is completely invisible to the end user. ADO handles all of the connections to the "closed" file.

Posting Permissions

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