#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Using Access Caption as Title


    I have an Access database that gets info from an Excel spreadsheet and places it in tbl1. I have built an asp page that loads information from tbl1 in my Access database. The code below is set to get the info from Field1 and I have repeated it for Field1 to Field16. Additionally within my Access database I insert caption information which is the column titles from the spreadsheet.

    Code:
    sql = "SELECT * FROM tbl1 "
    
    If Not IsEmpty(Request("FIELD1")) Then
    	Dim strFIELD1
    	strFIELD1 = Trim(Request("FIELD1"))
    	
    	If strFIELD1 <> "" Then
    		If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
    		sql = sql & "(FIELD1 LIKE '%" & Replace(strFIELD1, "'", "''") & "%') "
    	End If
    End If
    As part of my asp page there are column titles in HTML that at the moment are hand typed in. The code below shows a few title in my HTML page.

    Code:
    <td width="5%>Record No</td>
    <td width="5%>Cost</td>
    <td width="5%>Address</td>
    Is there an asp code that could extract all the captions from the Access database and insert them into the HTML section of the page?

    Hope this makes sense
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    If by captions you mean the column names in the db, yes you can get them programatically. Most databases provide a special view INFORMATION_SCHEMA that you can query for table names, column names, etc.

    There may be examples in this forum, a search here or google will find you some sample code.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    12
    Rep Power
    0
    Try following code:

    <table>
    <% for each field in rsTable.Fields %>
    <th bgcolor="#949494"><strong><%= field.Name %></strong></th> <% next %> </tr> <%do until rsTable.EOF %> <tr> <% for each field in rsTable.Fields %> <td bgcolor="#E2E2E2" height="23"><%= field.Value %></td> <% next %> </tr> <% rsTable.MoveNext rowCount=rowCount+1 loop rsTable.Close set rsTable=Nothing %> </table>
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0
    This: http://www.shotdev.com/asp/asp-access/asp-access-get-field-name/

IMN logo majestic logo threadwatch logo seochat tools logo