VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Access Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 03-07-2012, 03:58 AM   #1
jalexm

 
Joined: Mar 2012
Posts: 4
Kb Entries: 0
Articles: 0
Copying Caption to Description

Hello.
Iīm creating a VB app. to manipulate an Access database. The database has no form and no user interface. This is done by VB app.
I need to get the field/column Captions from each table defined in database but they are not available to ADO/ADOX.
One solution is to copy them to Description property since this one is available to ADO/ADOX. The problem is how to do it. Also, it needs to be done everytime the database is opened by VB app. (other developers here may change the captions and forget to warn).
I think some VBA code will solve this, but I donīt have any idea how to do it.
Please, can you help?
Thanks.

Local Time: 09:09 PM
Local Date: 05-20-2013

 
Reply With Quote Top
Old 03-07-2012, 05:20 AM   #2
mohanvijay
 
mohanvijay's Avatar

 
Joined: Aug 2010
Posts: 266
Kb Entries: 2
Articles: 0
Try this to get column details in Access

VBA:
Dim DB As ADODB.Connection Dim RS As ADODB.Recordset Set DB = New ADODB.Connection Set RS = New ADODB.Recordset DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=your access database;" Set RS = DB.OpenSchema(adSchemaColumns) ' RS contains details of columns RS.Close Set RS = Nothing DB.Close Set DB = Nothing
VBA tags courtesy of www.thecodenet.com

Local Time: 10:39 AM
Local Date: 05-21-2013
Location:

 
Reply With Quote Top
Old 03-07-2012, 05:27 AM   #3
jalexm

 
Joined: Mar 2012
Posts: 4
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: mohanvijay
Try this to get column details in Access

VBA:
Dim DB As ADODB.Connection Dim RS As ADODB.Recordset Set DB = New ADODB.Connection Set RS = New ADODB.Recordset DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=your access database;" Set RS = DB.OpenSchema(adSchemaColumns) ' RS contains details of columns RS.Close Set RS = Nothing DB.Close Set DB = Nothing
VBA tags courtesy of www.thecodenet.com


Sorry, this code is not a solution to this problem. Caption property is not available to Jet. If so I could get it uising my VB app. Only Description is available. Thatīs why I need to copy Captions to Descriptions. Any idea?

Local Time: 09:09 PM
Local Date: 05-20-2013

 
Reply With Quote Top
Old 03-07-2012, 07:05 AM   #4
mohanvijay
 
mohanvijay's Avatar

 
Joined: Aug 2010
Posts: 266
Kb Entries: 2
Articles: 0
Use DAO instead of ADO

VBA:
Dim DE As DAO.DBEngine Dim DB As DAO.Database Dim DB_Table As DAO.TableDef Dim Col_Caption As Field Dim T_Str As String Dim T_Str As String Set DE = New DAO.DBEngine Set DB = DE.OpenDatabase("F:\Finaln\ff.mdb") 'change to your path Set DB_Table = DB.TableDefs("data_led") ' set table name On Error Resume Next For Each Col_Caption In DB_Table.Fields T_Str = Col_Caption.Properties("Caption").Value 'get caption vale Next On Error Goto 0 Set Col_Caption = Nothing Set DB_Table = Nothing DB.Close Set DB = Nothing Set DE = Nothing
VBA tags courtesy of www.thecodenet.com

Local Time: 10:39 AM
Local Date: 05-21-2013
Location:

 
Reply With Quote Top
Old 03-07-2012, 09:29 AM   #5
jalexm

 
Joined: Mar 2012
Posts: 4
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: mohanvijay
Use DAO instead of ADO

VBA:
Dim DE As DAO.DBEngine Dim DB As DAO.Database Dim DB_Table As DAO.TableDef Dim Col_Caption As Field Dim T_Str As String Dim T_Str As String Set DE = New DAO.DBEngine Set DB = DE.OpenDatabase("F:\Finaln\ff.mdb") 'change to your path Set DB_Table = DB.TableDefs("data_led") ' set table name On Error Resume Next For Each Col_Caption In DB_Table.Fields T_Str = Col_Caption.Properties("Caption").Value 'get caption vale Next On Error Goto 0 Set Col_Caption = Nothing Set DB_Table = Nothing DB.Close Set DB = Nothing Set DE = Nothing
VBA tags courtesy of www.thecodenet.com


Perfect!!!
I canīt believe this is not available in ADO/ADOX.

Do you know how to get a list of tables using DAO?
One more question: is there any problem using DAO and ADO/ADOX in the same app in VB?
Thanks.

Last edited by jalexm : 03-07-2012 at 09:46 AM.

Local Time: 09:09 PM
Local Date: 05-20-2013

 
Reply With Quote Top
Old 03-07-2012, 07:48 PM   #6
mohanvijay
 
mohanvijay's Avatar

 
Joined: Aug 2010
Posts: 266
Kb Entries: 2
Articles: 0
To get list of tables

VBA:
Dim DB_Table As DAO.TableDef For Each DB_Table In DB.TableDefs MsgBox DB_Table.Name Next
VBA tags courtesy of www.thecodenet.com

i think no problem comes if using DAO - ADO - ADOX on same application

Local Time: 10:39 AM
Local Date: 05-21-2013
Location:

 
Reply With Quote Top
Old 03-08-2012, 07:02 AM   #7
jalexm

 
Joined: Mar 2012
Posts: 4
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: mohanvijay
To get list of tables

VBA:
Dim DB_Table As DAO.TableDef For Each DB_Table In DB.TableDefs MsgBox DB_Table.Name Next
VBA tags courtesy of www.thecodenet.com


Great!!!
Last question: in the code above, how to get the type (VIEW, TABLE, etc.) of a table? Is this possible using DAO?
Many thanks.

Local Time: 09:09 PM
Local Date: 05-20-2013

 
Reply With Quote Top
Old 03-08-2012, 07:36 AM   #8
Movian
 
Movian's Avatar

 
Joined: Aug 2008
Posts: 310
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: mohanvijay
To get list of tables

VBA:
Dim DB_Table As DAO.TableDef For Each DB_Table In DB.TableDefs MsgBox DB_Table.Name Next
VBA tags courtesy of www.thecodenet.com

i think no problem comes if using DAO - ADO - ADOX on same application


I would just like to mention that if you DO use ADO and DAO in the same project its very important to fully qualify everything.

eg
VBA:
Dim myrs As New adodb.recordset
VBA tags courtesy of www.thecodenet.com
NOT
VBA:
Dim myrs As New recordset
VBA tags courtesy of www.thecodenet.com

As this will cause problems! Aside from that as far as i know there are no other problems.


"From the ashes of disaster grow the roses of success" - Chitty chitty bang bang

"I fear not the man who has 10,000 kicks practiced once. I fear the man who has 1 kick practiced 10,000 times" - Bruce Lee

Local Time: 12:09 AM
Local Date: 05-21-2013

 
Reply With Quote Top
Reply



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 10:09 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright Đ 2004 - 2012 VBA Express