Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2006, 06:58 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Column Name from ADODB Recordset

Hi ,
I have few columns in table (and few rows) , but the columns has different specific names . I also have Adodb connection , and a recordset - and i go through the rows in a loop . Now i want to get every time the name of the column and to use it in the format :
rsRecords!columnName
where column name is what i want to know how to get .

I also have another question :
i created by wizard dynamic changed text boxes from specific table . I need to know how to attach to each of these columns event OnChange for validating (or is there any other way to do validating?) input in each text box in form .
How to implement this ?


Paula .


Reply With Quote
  #2 (permalink)  
Old February 10th, 2006, 08:36 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can do this by using this sort of code:

rsRecords.Fields(i)

where i is the number of the column, starting with 0, of course.

I don't understand your second question. You do validation at the table level, or you use regular expressions (See msdn.microsoft.com regular expressions reference) to check for values entered.

mmcdonal
Reply With Quote
  #3 (permalink)  
Old February 10th, 2006, 09:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

rsRecords.Field(i) syntax will get you the value of the recordset's field, but not the name of the table column. To get the name of the table column using ADO/ADOX, you have two oprions: open a second recordset set and populate it with the ADO OpenSchema metheod, or use an ADOX Table object's Column property.

1. Using ADODB.Connection and OpenSchema method
Code:
Sub ListTableAndColumnNamesADO()
  Dim Conn As New ADODB.Connection
  Dim TablesSchema As ADODB.Recordset
  Dim ColumnsSchema As ADODB.Recordset

  'Open connection you want To get database objects
  Conn.Provider = "MSDASQL"
  Conn.Open "DSN=...;Database=...;", "UID", "PWD"

  'Get all database tables.
  Set TablesSchema = Conn.OpenSchema(adSchemaTables) 
  Do While Not TablesSchema.EOF
    'Get all table columns.
    Set ColumnsSchema = Conn.OpenSchema(adSchemaColumns, _
      Array(Empty, Empty, "" & TablesSchema("TABLE_NAME")))
    Do While Not ColumnsSchema.EOF
      Debug.Print TablesSchema("TABLE_NAME") & ", " & _
        ColumnsSchema("COLUMN_NAME")
      ColumnsSchema.MoveNext
    Loop
    TablesSchema.MoveNext
  Loop
End Sub
TablesSchema fields : TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, TABLE_GUID, DESCRIPTION, TABLE_PROPID, DATE_CREATED, DATE_MODIFIED

ColumnsSchema fields : TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_GUID, COLUMN_PROPID, ORDINAL_POSITION, COLUMN_HASDEFAULT, COLUMN_DEFAULT, COLUMN_FLAGS, IS_NULLABLE, DATA_TYPE, TYPE_GUID, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, DATETIME_PRECISION, CHARACTER_SET_CATALOG, CHARACTER_SET_SCHEMA, CHARACTER_SET_NAME, COLLATION_CATALOG, COLLATION_SCHEMA, COLLATION_NAME, DOMAIN_CATALOG, DOMAIN_SCHEMA, DOMAIN_NAME, DESCRIPTION, SS_DATA_TYPE

2. Using ADOX.Catalog and its collections

Code:
Sub ListTableandColumNamesADOX()
  Dim Conn As New ADODB.Connection

  'Open connection you want To get database objects
  Conn.Provider = "MSDASQL"
  Conn.Open "DSN=...;Database=...;", "UID", "PWD"

  'Create catalog object
  Dim Catalog As New ADOX.Catalog
  Set Catalog.ActiveConnection = Conn

  'List tables And columns
  Dim Table As ADOX.Table, Column As ADOX.Column
  For Each Table In Catalog.Tables
    For Each Column In Table.Columns
      Debug.Print Table.Name & ", " & Column.Name
    Next
  Next
End Sub
Bob

Reply With Quote
  #4 (permalink)  
Old February 10th, 2006, 12:08 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks ,
the ADOX method was useful with what i wanted .


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB.Recordset (0x800A0CB3) hbansal Classic ASP Databases 3 June 28th, 2008 01:38 AM
ADODB.Recordset error lance Wrox Book Feedback 2 February 23rd, 2007 02:37 PM
ADODB Recordset sporkman43 Classic ASP Basics 4 November 9th, 2006 04:51 AM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
How to get adodb.record from adodb.recordset John Pennington Pro VB Databases 1 November 20th, 2004 06:17 AM



All times are GMT -4. The time now is 10:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.