A Useful Retrieval Procedure

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
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS