Results 1 to 9 of 9
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use this conn:

    cn.ConnectionString = "Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & DATA_BASE & ";Data Source=xxxxxxx"
    cn.Open

    and i know the name of table of DATA_BASE similar MyTable

    How to retive the name of fileds in Table MyTable????

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can open a recordset rst on MyTable, then use a loop like this:

    Code:
    Dim fld As ADODB.Field
    Dim strName As String
    For Each fld In rst.Fields
      strName = fld.Name
      ...
      ...
    Next fld

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I think the method Hans describes is fastest, particularly because you have the table open already. If it doesn't work, you can try the ADOX library: ADO Extensions for Data Definition Language and Security (ADOX). I personally find ADOX hard to use, but my database work is quite limited, so that could explain it.

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    You can open a recordset rst on MyTable, then use a loop like this:

    Code:
    Dim fld As ADODB.Field
    Dim strName As String
    For Each fld In rst.Fields
      strName = fld.Name
      ...
      ...
    Next fld
    Hi Hans...
    Based the code is possible to write into a text file similar c:\myfile.txt the name of fileds separated from ";"?
    I want to use to make the header of CSV text file.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Yes. Use code like this:

    Code:
    ...
    Dim fld As ADODB.Field
    Dim strName As String
    Dim strLine As String
    Dim f As Integer
    
    ' Create text file
    f = FreeFile
    Open "C:\MyFile.txt" For Output As #f
    
    For Each fld In rst.Fields
      ' Get name of field
      strName = fld.Name
      ' Append to strLine
      strLine = strLine & ";" & strName
    Next fld
    
    ' Write strLine to file, omitting the first semicolon ;
    Print #f, Mid(strLine, 2)
    
    ' Close text file
    Close #f
    ...

  6. #6
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    Yes. Use code like this:

    Code:
    ...
    Dim fld As ADODB.Field
    Dim strName As String
    Dim strLine As String
    Dim f As Integer
    
    ' Create text file
    f = FreeFile
    Open "C:\MyFile.txt" For Output As #f
    
    For Each fld In rst.Fields
      ' Get name of field
      strName = fld.Name
      ' Append to strLine
      strLine = strLine & ";" & strName
    Next fld
    
    ' Write strLine to file, omitting the first semicolon ;
    Print #f, Mid(strLine, 2)
    
    ' Close text file
    Close #f
    ...
    wow!

    But the next prob is:
    i want to write (after this header) also the value of recordset separeted from ";" how to? i not have any idea.
    In effet i wat to loop into recorset and create the rest of CSV

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can export from Access to a .csv file.
    You can use CopyFromRecordset to import from Access into Excel; you can save the result as a .csv file.
    So why should we write code for you for something that can already be done?

  8. #8
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    You can open a recordset rst on MyTable, then use a loop like this:

    Code:
    Dim fld As ADODB.Field
    Dim strName As String
    For Each fld In rst.Fields
      strName = fld.Name
      ...
      ...
    Next fld
    hi... is possible during this loop to know also the property of each filed?
    Similar is is numeric, double text ecc....

  9. #9
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sal21 View Post
    hi... is possible during this loop to know also the property of each filed?
    Similar is is numeric, double text ecc....
    Have a look at Allen Browne's TableInfo() function
    Francois

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •