Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default ACCESS TABLE EXISTS-ADO

Using ADO in EXCEL VBA, I'd like to check if an Access
table exists before I run my query. Is this possible
using ADO?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default ACCESS TABLE EXISTS-ADO

Hi

If you have reference to the ADO Ext library then this function (from MSDN)
can be modified:

Sub ADOListTables()

Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table

' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=.\NorthWind.mdb;"

' Loop through the tables in the database and print their name
For Each tbl In cat.Tables
If tbl.Type < "VIEW" Then Debug.Print tbl.Name
Next

End Sub

Otherwise, you could just search the table for anything. If empty or error
then it doesn't exist:

Function TableXists(strTableName As String) As Boolean
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=.\NorthWind.mdb;"
On Error GoTo Bad
rst.Open _
"SELECT * FROM " & strTableName, _
cnn, adOpenForwardOnly, adLockReadOnly
TableXists = Not (rst.EOF)

rst.Close
Exit Function
Bad:
TableXists = False
End Function

Sub test()
MsgBox TableXists("Customers")
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"AL" skrev i melding
...
Using ADO in EXCEL VBA, I'd like to check if an Access
table exists before I run my query. Is this possible
using ADO?

Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default ACCESS TABLE EXISTS-ADO

Hi Harald,

I've been having trouble reaching you by email. Could you send me one
please?

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default ACCESS TABLE EXISTS-ADO

Sure. Sorry. Will do.

Best wishes Harald


"Jan Karel Pieterse" skrev i melding
...
Hi Harald,

I've been having trouble reaching you by email. Could you send me one
please?

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default ACCESS TABLE EXISTS-ADO

Hi Harald,

Will do.


Thanks.

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ACCESS TABLE EXISTS-ADO

"Harald Staff" wrote in message ...

you could just search the table for anything. If empty or error
then it doesn't exist


Harold, Surely an empty table *does* exist?!

--
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default ACCESS TABLE EXISTS-ADO

Harold, Surely an empty table *does* exist?!

Definitely :-), but our friend wants do run this before doing a query. I
assume this table has something to do with the query, and if so it would
return nothing more from an empty table than from a non-existing one.

But I may be wrong, perhaps he's just an unusually exploring and curious
person <bg

Best wishes Harald


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ACCESS TABLE EXISTS-ADO

How about trying a query which uses the table and see whether you get
an error, either a VBA run-time error and/or look in the ADO
Connection object's Errors collection. Use a query with low
processing: no need to return any rows or columns e.g.

SELECT 1 FROM MyTable WHERE 0=1

--

"AL" wrote in message ...
Using ADO in EXCEL VBA, I'd like to check if an Access
table exists before I run my query. Is this possible
using ADO?

Thanks in advance.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup only when data exists in table BabyMc[_2_] Excel Discussion (Misc queries) 1 June 9th 09 11:52 AM
Pivot Table from Access DB dale1948 Excel Worksheet Functions 3 September 19th 07 11:56 PM
Is there any way to export a .xls table to Access .mdb without Acc Mr. Analogy Excel Discussion (Misc queries) 0 February 1st 07 12:05 AM
Multiple MS Access table sources for pivot table fbj Excel Discussion (Misc queries) 5 August 15th 05 03:41 PM
read Access table from VBA Ron[_13_] Excel Programming 5 December 28th 03 02:43 PM


All times are GMT +1. The time now is 07:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"