Completely Reusable SQL Server/XML Generator !
This is a really simple way of grabbing the column details for all the user tables in a SQL Server database, and converting those details to XML. If you wanted to get a little creative, you could re-use this with XSL to create SQL and ASP templates for your apps.
Original Author: Brandon McPherson
Inputs
The only real 'condition' is that you should have a default database set up in your connection.
Assumptions
I know this works in SQL Server 2000 and version 7.0, but I won't guarantee anything before that (I don't have copies of the system tables to check).
Returns
XML data outlining the column information for the tables in a database.
Code
Private Sub Command1_Click()
X = PrintMSHGrid(MSHFlexGrid1)
End Sub
Public Function PrintMSHGrid(ByVal GridToPrint As MSHFlexGrid) As Long
'This function retrieves data from MSHFlexGrid and prints it directly to the
'printer. It uses MyArray to store the distance between columns. The max number
'of columns is 50, but it can be increased if there is a need.
'Print information from mshflexgrid
Dim MyRows, MyCols As Integer 'for-loop counters
Dim MyText As String 'text to be printed
Dim Titles As String 'column titles
Dim Header As String 'page headers
Dim MyLines As Integer 'number of lines for portrait/landscape
Dim LLCount As Integer 'temporary line counter
Dim MyArray(50) As Integer
Screen.MousePointer = vbHourglass
Titles = ""
LLCount = 0
Header = " - Page: " 'setup page header
'get column headers
For MyCols = 0 To GridToPrint.Cols - 1
MyArray(MyCols) = Len(GridToPrint.ColHeaderCaption(0, MyCols)) + 15
Titles = Titles & Space(15) & GridToPrint.ColHeaderCaption(0, MyCols)
Next MyCols
'setup printer
Printer.Font.Size = 8 '8pts font size
Printer.Font.Bold = True 'titles to be bold
Printer.Font.Name = "Courier New" 'courier new font
'determine whether to print landscape or portrait
If (Len(MyText) > 120) Then 'landscape
Printer.Orientation = vbPRORLandscape
MyLines = 60
Else 'portrait
Printer.Orientation = vbPRORPortrait
MyLines = 85
End If
Printer.Print Header; Printer.Page
Printer.Print Titles
Printer.Font.Bold = False
'get column/row values
For MyRows = 1 To GridToPrint.Rows - 1
MyText = ""
GridToPrint.Row = MyRows
For MyCols = 0 To GridToPrint.Cols - 1
GridToPrint.Col = MyCols
MyText = MyText & GridToPrint.Text & Space(MyArray(MyCols) - Len(GridToPrint.Text))
Next MyCols
LLCount = LLCount + 1
If LLCount <= MyLines Then
Printer.Print MyText
Else
Printer.NewPage
Printer.Print Header; Printer.Page
Printer.Print Titles
Printer.Print MyText
LLCount = 0
End If
Next MyRows
Printer.EndDoc
Screen.MousePointer = vbNormal
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.