This procedure retrieves the table name, table id, column or fieldname, data type, the length of the field in bytes, and the order in which the fields were created. I use it as a data source for my MS Access utility. I also use it to get needed project development info.
To use it immediately, copy and paste the following to SQL ServerQuery Analyzer, choose the database you want to use and press ExecuteQuery (F5):
SELECT SO.name as [Table],SO.id as [Table ID],SC.name AS[Fieldname],Sc.xtype as [Storage Type],ST.name AS [DataType],SC.Length,colorder as [Order] FROM sysobjects SO INNER JOINsyscolumns SC ON SO.id=SC.id LEFT JOIN systypes ST ONSC.xtype=ST.xusertype WHERE SO.xtype='U' ORDER BY SO.name,SC.name
To use this for Access Data Projects, use this procedure in the RecordSource property of a form and run it. For example, place this code in your main form:
Dim frm as Form 'at the topmost (General) portion of the codePrivate Sub cmdListFields_Click() 'based on a cmdListFields button in theMain FormOn Error GoTo ErrHandler Dim strTable As String Dim sQRY As String Set frm = New Form_ListForm 'use the name of the form you created tolist the Recordset strTable = InputBox("Please enter Table name: ", "Needs a Name","(Default Table)") If Len(strTable) > 0 Then sQRY = "SELECT SO.Name as [Table],SO.id as [Table ID],SC.Name AS[Fieldname], " sQRY = sQRY & "Sc.xtype as [Storage Type],ST.name AS [Type]," sQRY = sQRY & "SC.Length,colorder as [Order] FROM sysobjects SO " sQRY = sQRY & "INNER JOIN syscolumns SC ON SO.id=SC.id LEFT JOINsystypes ST " sQRY = sQRY & "ON SC.xtype=ST.xusertype WHERE SO.xtype='U' " sQRY = sQRY & " AND SO.Name = '" & strTable sQRY = sQRY & "' ORDER BY SC.name" frm.RecordSource = sQRY frm.Visible = True frm.SetFocus Else MsgBox "No table name provided." End IfExit SubErrHandler: MsgBox "Error: " & Err.Description Err.ClearEnd Sub