Results 1 to 5 of 5

Thread: [RESOLVED] [VBA/ADO] Check for database present

  1. #1

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Resolved [RESOLVED] [VBA/ADO] Check for database present

    Hi all

    I have an excel spreadsheet that pulls data out of Access via ADO

    ie
    Code:
    Set cn = New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDb & ";"
        Set rs = New ADODB.Recordset
     
        With rs
            Set .ActiveConnection = cn
            .Open strQry
    When these spreasheets are sent offsite I would like to put a check in for no database and if none just skip the on load routine to refresh the Excel data from the database.... how cleanly can I test for the database not being there? So the offsite doesnt see an error

    cheers George
    Last edited by Ggalla1779; Apr 12th, 2010 at 08:59 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [VBA/ADO] Check for database present

    Code:
    If Dir(strDb) = "" Then
      'file exists
    Else
      'it doesn't
    End If
    It sounds like you may also find it useful to read the article Why do errors crash my program, and how can I stop that from happening? (making an Error Handler) from our Classic VB FAQs (in the FAQ forum)

  3. #3

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: [VBA/ADO] Check for database present

    aha...thats crafty.... I coded it it then said no database...so I presume your comments are round the wrong way to see if I am awake!!!

    Thanks for help

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [VBA/ADO] Check for database present

    It always helps to understand the code (using the help etc as apt), rather than just assume it is doing the right thing... but it wasn't actually intentional, and was just due to a last-minute change of plan!

  5. #5

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: [VBA/ADO] Check for database present

    kk thats great I would not have thought of using dir...thats it all coded up and a yes / no message box to see if user wants to refresh data....thanks for your help

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