Look for full sourcode at: http://www.swingnote.com/downloads.php 'SQL2VB by Markus Diersbock '========================== 'This utility takes the structure of table and creates a VB Form 'that contains lables and textboxes for each column. The textbox 'property attributes are set to reflect the attributes of the 'column. ' 'A text file is also created with cut&paste code for two-way 'assignments ' 'Copyright(c)2002 Markus Diersbock. Private Sub cmdCreateForm_Click() cmdCreateForm.Enabled = False Dim connString As String Dim oConn As ADODB.Connection Dim oRs As ADODB.Recordset Set oConn = New ADODB.Connection Dim conObj As Object ' Replace the following with your Connection String code Set conObj = CreateObject("aaaConnString.clsConnString") connString = conObj.connString Set conObj = Nothing oConn.Open connString Dim strFileName As String Dim lngNextHandle As Long Dim lngDataHandle As Long Dim intNoFields As Integer Dim strDBTableName As String Dim intTabIndex As Integer Dim lngTopPositionLabel As Long Dim lngTopPositionText As Long strDBTableName = txtTableName.Text strFileName = strDBTableName Set oRs = oConn.Execute("SELECT * FROM " & strDBTableName) ' Open file that hold assignments code for later use lngDataHandle = FreeFile Open App.Path & "\Data\" & strFileName & ".txt" For Output As #lngDataHandle ' Open VB form file lngNextHandle = FreeFile Open App.Path & "\Data\" & strFileName & ".frm" For Output As #lngNextHandle ' .Type = Field DataType If oConn.Errors.Count = 0 Then lngTopPositionLabel = 350 lngTopPositionText = 300 Call WriteHeader(strDBTableName, lngNextHandle) For intNoFields = 0 To oRs.Fields.Count - 1 intTabIndex = intNoFields + 1 Debug.Print "Name: " & oRs.Fields(intNoFields).Name & " - Size:" & oRs.Fields(intNoFields).DefinedSize ' Write to VB Form file Print #lngNextHandle, " Begin VB.Label LABEL_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name Print #lngNextHandle, " Alignment = 0 'Left Justify" Print #lngNextHandle, " Caption =" & DOUBLE_QUOTE & Replace(oRs.Fields(intNoFields).Name, "_", " ") & ":" & DOUBLE_QUOTE Print #lngNextHandle, " Height = 225" Print #lngNextHandle, " Left = 150" Print #lngNextHandle, " TabIndex = 0" Print #lngNextHandle, " Top = " & lngTopPositionLabel Print #lngNextHandle, " Width = 1680" Print #lngNextHandle, " End" Print #lngNextHandle, " Begin VB.TextBox TEXT_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name Print #lngNextHandle, " Height = 285" Print #lngNextHandle, " Left = 2000" Print #lngNextHandle, " MaxLength = " & Str(oRs.Fields(intNoFields).DefinedSize) Print #lngNextHandle, " TabIndex = " & intTabIndex Print #lngNextHandle, " Text = " & DOUBLE_QUOTE & "TEXT_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name & DOUBLE_QUOTE Print #lngNextHandle, " Top = " & lngTopPositionText Print #lngNextHandle, " Width = " & Str(oRs.Fields(intNoFields).DefinedSize * 130) Print #lngNextHandle, " End" lngTopPositionLabel = lngTopPositionLabel + 400 lngTopPositionText = lngTopPositionText + 400 Next Call WriteFooter(strDBTableName, lngNextHandle) For intNoFields = 0 To oRs.Fields.Count - 1 ' Write to VB Form file Print #lngNextHandle, " TEXT_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name & ".Text = " & DOUBLE_QUOTE & DOUBLE_QUOTE ' Write to assignments text file Print #lngDataHandle, "TEXT_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name & ".Text = objXXX." & Replace(oRs.Fields(intNoFields).Name, "_", "") Next ' Write to VB Form file Print #lngNextHandle, "End Sub" ' Write to assignments text file Print #lngDataHandle, " " Print #lngDataHandle, "=============================================================================" Print #lngDataHandle, " " For intNoFields = 0 To oRs.Fields.Count - 1 ' Write to assignments text file Print #lngDataHandle, "objXXX." & Replace(oRs.Fields(intNoFields).Name, "_", "") & " = " & "TEXT_" & strDBTableName & "_" & oRs.Fields(intNoFields).Name & ".Text" Next End If Close #lngNextHandle Close #lngDataHandle Set oRs = Nothing Set oConn = Nothing cmdCreateForm.Enabled = True End Sub