Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-06-2007, 02:26 PM
willjones willjones is offline
Registered User
 
Join Date: Mar 2007
Posts: 13
willjones is on a distinguished road
Describe table problem

This should be a really simple thing to do, but it isn't working.

I want to determine all the column names in a table or at least all column names with a primary key. I attempted to do this OpenRecordset("desc " & tablename & ";", dbOpenSnapShot) but I get an error. (My tablename is a linked table to an Oracle table.) I'm using Oracle 10g. When I open TOAD and type desc tablename; I get a pop-up window describing the table instead of a record set with table names in it.

I thought about just saying select * from tablename; and then for each field in rs.Fields reading the field.Name. This worked great, until I came across an empty table. Nothing is returned from select * in that case! So then I thought well I could insert a row just before the query and then delete it again, but I can't even do this, because I don't know what the primary keys are on the table!

Basically if I could just do a desc or describe on the table in code, I would be fine, but I have not been able to figure out how to do this.

Please help...

Thanks.
Reply With Quote
Sponsored Links
  #2  
Old 08-07-2007, 08:45 AM
tehNellie tehNellie is offline
Registered User
 
Join Date: Apr 2007
Location: Bristol, UK
Posts: 426
tehNellie is on a distinguished road
Code:
sub ColumnName() 
  Dim db As DAO.Database, td As DAO.TableDef, fld As DAO.Field
  Dim strTblname as String

  strTblname = Inputbox( "Enter Table Name")
  Set db = currentdb()
  Set td = db.TableDefs(strTblname)

  For Each fld In td.Fields
    msgbox fld.name
  Next fld
  
  Set td =  Nothing
  Set db = Nothing
End sub
I think should do it to return all column names in a given table

Last edited by tehNellie; 08-07-2007 at 08:50 AM.. Reason: typo alert!
Reply With Quote
  #3  
Old 08-07-2007, 10:43 AM
willjones willjones is offline
Registered User
 
Join Date: Mar 2007
Posts: 13
willjones is on a distinguished road
TableDefs

Thanks for that info... TableDefs works great for when you have the table defined or linked to in Access, but my tables aren't always guaranteed to be defined or even linked to in my Access mdb. When I attempted to use TableDefs on my external ODBC connection I got a run-time error '3251' "Operation is not supported for this type of object." I'm still not sure how you would do it if you just have a database connection to an external database and want to execute an OpenRecordSet query on it to return the description (or DESCRIBE) of a table. I discovered that DESC is not a standard SQL command and can't be relied upon from looking at this thread (http://root.cern.ch/root/roottalk/roottalk01/1558.html).

Fortunately for me, I finally realized that in my specific case I didn't really have to know all the columns in the table if I knew the table was empty. (This might not always be true in every case though.) So I was able to just check if the table was empty by doing a select count(*) from table; and if 0 then skip over. If it was not empty then I parsed through the result set looking at each Field.Name to determine the column names. So, really I was able to side step my problem. (If anyone else thinks of any further info regarding this though, go ahead and post it in case someone else has a problem like this in the future.) Thanks again for your input.
Reply With Quote
  #4  
Old 08-08-2007, 02:07 AM
tehNellie tehNellie is offline
Registered User
 
Join Date: Apr 2007
Location: Bristol, UK
Posts: 426
tehNellie is on a distinguished road
Your other option is to use the ODBC connection to query the Oracle Database directly. You can then use DESC and return the results to a recordset for manipulation etc.
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with saving changes on Table Peter2222 Tables 5 10-31-2005 09:46 AM
Update table via form problem marathonlady Forms 1 09-01-2005 03:44 PM
Query to fill in blanks within a table? Maybe some other way? robjones23 Queries 11 03-21-2005 02:10 AM
Help with Relationships and table design: Bill Harrison Tables 7 01-12-2005 05:44 AM
Complicated Table Problem k209310 Macros 0 09-23-2002 04:50 AM


All times are GMT -8. The time now is 10:02 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World