[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
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)
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
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! :D
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