home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / dfd2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  25.4 KB  |  735 lines

  1. VERSION 4.00
  2. Begin VB.Form frmDFD 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Data Form Designer"
  5.    ClientHeight    =   4065
  6.    ClientLeft      =   1155
  7.    ClientTop       =   2505
  8.    ClientWidth     =   6135
  9.    Height          =   4470
  10.    HelpContextID   =   2018517
  11.    Icon            =   "DFD.frx":0000
  12.    Left            =   1095
  13.    LinkTopic       =   "Form1"
  14.    LockControls    =   -1  'True
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   4065
  18.    ScaleWidth      =   6135
  19.    Top             =   2160
  20.    Width           =   6255
  21.    Begin VB.CheckBox chkOnScreen 
  22.       Caption         =   "On Screen"
  23.       Height          =   195
  24.       Left            =   810
  25.       TabIndex        =   17
  26.       Top             =   3345
  27.       Width           =   1665
  28.    End
  29.    Begin VB.ListBox lstOLECtls 
  30.       Height          =   615
  31.       Left            =   120
  32.       TabIndex        =   16
  33.       Top             =   3360
  34.       Visible         =   0   'False
  35.       Width           =   615
  36.    End
  37.    Begin VB.CommandButton cmdMoveFields 
  38.       Caption         =   "<<"
  39.       Height          =   375
  40.       Index           =   3
  41.       Left            =   2760
  42.       TabIndex        =   7
  43.       Top             =   2880
  44.       Width           =   495
  45.    End
  46.    Begin VB.CommandButton cmdMoveFields 
  47.       Caption         =   "<"
  48.       Height          =   375
  49.       Index           =   2
  50.       Left            =   2760
  51.       TabIndex        =   6
  52.       Top             =   2400
  53.       Width           =   495
  54.    End
  55.    Begin VB.CommandButton cmdMoveFields 
  56.       Caption         =   ">"
  57.       Height          =   375
  58.       Index           =   1
  59.       Left            =   2760
  60.       TabIndex        =   5
  61.       Top             =   1920
  62.       Width           =   495
  63.    End
  64.    Begin VB.CommandButton cmdMoveFields 
  65.       Caption         =   ">>"
  66.       Height          =   375
  67.       Index           =   0
  68.       Left            =   2760
  69.       TabIndex        =   4
  70.       Top             =   1440
  71.       Width           =   495
  72.    End
  73.    Begin VB.ListBox lstIncludedFields 
  74.       DragIcon        =   "DFD.frx":030A
  75.       Height          =   1785
  76.       Left            =   3360
  77.       MultiSelect     =   2  'Extended
  78.       TabIndex        =   3
  79.       Top             =   1440
  80.       Width           =   2655
  81.    End
  82.    Begin VB.CommandButton cmdBuildForm 
  83.       Caption         =   "&Build the Form"
  84.       Height          =   375
  85.       Left            =   720
  86.       TabIndex        =   8
  87.       Top             =   3600
  88.       Width           =   1695
  89.    End
  90.    Begin VB.ComboBox cboRecordSource 
  91.       Height          =   300
  92.       Left            =   1680
  93.       TabIndex        =   1
  94.       Top             =   480
  95.       Width           =   4335
  96.    End
  97.    Begin VB.ListBox lstFields 
  98.       DragIcon        =   "DFD.frx":0614
  99.       Height          =   1785
  100.       Left            =   120
  101.       MultiSelect     =   2  'Extended
  102.       TabIndex        =   2
  103.       Top             =   1440
  104.       Width           =   2535
  105.    End
  106.    Begin VB.TextBox txtFormName 
  107.       Height          =   285
  108.       Left            =   2760
  109.       MaxLength       =   8
  110.       TabIndex        =   0
  111.       Top             =   120
  112.       Width           =   1095
  113.    End
  114.    Begin VB.CommandButton cmdClose 
  115.       Caption         =   "&Close"
  116.       Height          =   375
  117.       Left            =   3600
  118.       TabIndex        =   9
  119.       Top             =   3600
  120.       Width           =   1695
  121.    End
  122.    Begin VB.Line Line1 
  123.       BorderWidth     =   3
  124.       X1              =   120
  125.       X2              =   6000
  126.       Y1              =   1080
  127.       Y2              =   1080
  128.    End
  129.    Begin VB.Label lblLabels 
  130.       Alignment       =   2  'Center
  131.       Caption         =   "Select a Table/QueryDef from the list or enter a SQL statement."
  132.       Height          =   195
  133.       Index           =   4
  134.       Left            =   120
  135.       TabIndex        =   15
  136.       Top             =   840
  137.       Width           =   5925
  138.    End
  139.    Begin VB.Label lblLabels 
  140.       AutoSize        =   -1  'True
  141.       Caption         =   "Included Fields: "
  142.       Height          =   195
  143.       Index           =   10
  144.       Left            =   3360
  145.       TabIndex        =   14
  146.       Top             =   1200
  147.       Width           =   1155
  148.    End
  149.    Begin VB.Label lblLabels 
  150.       AutoSize        =   -1  'True
  151.       Caption         =   " Drag/Drop to Change Order "
  152.       Height          =   195
  153.       Index           =   7
  154.       Left            =   3360
  155.       TabIndex        =   13
  156.       Top             =   3300
  157.       Width           =   2070
  158.    End
  159.    Begin VB.Label lblLabels 
  160.       AutoSize        =   -1  'True
  161.       Caption         =   "RecordSource: "
  162.       Height          =   195
  163.       Index           =   6
  164.       Left            =   105
  165.       TabIndex        =   12
  166.       Top             =   540
  167.       Width           =   1125
  168.    End
  169.    Begin VB.Label lblLabels 
  170.       AutoSize        =   -1  'True
  171.       Caption         =   "Available Fields: "
  172.       Height          =   195
  173.       Index           =   3
  174.       Left            =   120
  175.       TabIndex        =   11
  176.       Top             =   1200
  177.       Width           =   1185
  178.    End
  179.    Begin VB.Label lblLabels 
  180.       AutoSize        =   -1  'True
  181.       Caption         =   "Form Name (w/o Extension): "
  182.       Height          =   195
  183.       Index           =   0
  184.       Left            =   120
  185.       TabIndex        =   10
  186.       Top             =   120
  187.       Width           =   2055
  188.    End
  189. Attribute VB_Name = "frmDFD"
  190. Attribute VB_Creatable = False
  191. Attribute VB_Exposed = False
  192. Dim mrecRS As Recordset
  193. Private Sub cboRecordSource_Change()
  194.   Set mrecRS = Nothing
  195.   lstFields.Clear
  196.   lstIncludedFields.Clear
  197. End Sub
  198. Private Sub cboRecordSource_Click()
  199.   Call cboRecordSource_LostFocus
  200. End Sub
  201. Private Sub cboRecordSource_LostFocus()
  202.   On Error GoTo RSErr
  203.   Dim i As Integer
  204.   Dim fld As Field
  205.   If Len(cboRecordSource.Text) = 0 Then Exit Sub
  206.   Screen.MousePointer = 11
  207.   If mrecRS Is Nothing Then
  208.     Set mrecRS = gdbCurrentDB.OpenRecordset(cboRecordSource.Text)
  209.     For Each fld In mrecRS.Fields
  210.       lstFields.AddItem fld.Name
  211.     Next
  212.   ElseIf mrecRS.Name <> cboRecordSource.Text Then
  213.     lstFields.Clear
  214.     lstIncludedFields.Clear
  215.     Set mrecRS = gdbCurrentDB.OpenRecordset(cboRecordSource.Text)
  216.     For Each fld In mrecRS.Fields
  217.       lstFields.AddItem fld.Name
  218.     Next
  219.   End If
  220.   Screen.MousePointer = 0
  221.   Exit Sub
  222. RSErr:
  223.   Screen.MousePointer = 0
  224.   MsgBox Error$
  225.   Exit Sub
  226. End Sub
  227. Sub cmdBuildForm_Click()
  228.   If Len(txtFormName.Text) = 0 Then
  229.     MsgBox "Form Name cannot be blank!", 16
  230.     txtFormName.SetFocus
  231.     Exit Sub
  232.   End If
  233.   If Len(cboRecordSource.Text) = 0 Then
  234.     MsgBox "You must enter a RecordSource!", 16
  235.     Exit Sub
  236.   End If
  237.   If lstIncludedFields.ListCount = 0 Then
  238.     MsgBox "You must include some Columns!", 16
  239.     Exit Sub
  240.   End If
  241.   If chkOnScreen.Value = vbChecked Then
  242.     BuildFormOnScreen
  243.   Else
  244.     BuildFormFile
  245.   End If
  246. End Sub
  247. Sub BuildFormOnScreen()
  248.   On Error GoTo BuildErr
  249.   Dim i As Integer
  250.   Dim sTmp As String
  251.   Dim nNumFlds As Integer
  252.   Dim frmNewForm As Object
  253.   Dim ctlNewControl As Object
  254.   Dim nButtonTop As Integer
  255.   nNumFlds = lstIncludedFields.ListCount
  256.   lstOLECtls.Clear
  257.   'create the new form
  258.   Set frmNewForm = gobjIDEAppInst.ActiveProject.AddFormTemplate()
  259.   'form height = 320 * numflds + 1260 for buttons and data control
  260.   'form width = 5640
  261.   With frmNewForm
  262.     .Properties!Appearance = 1
  263.     .Properties!Caption = Left(mrecRS.Name, 32)
  264.     .Properties!Height = 1115 + (nNumFlds * 320)
  265.     .Properties!Left = 1050
  266.     .Properties!Name = "frm" & txtFormName.Text
  267.     .Properties!Width = 5640
  268.   End With
  269.   'labels.left = 120, .width = 1815, .height = 255
  270.   'fields.left = 2040, .width = 3375, .height = 285
  271.   For i = 0 To nNumFlds - 1
  272.     sTmp = lstIncludedFields.List(i)
  273.     Set ctlNewControl = frmNewForm.ControlTemplates.Add("Label")
  274.     With ctlNewControl
  275.       .Properties!Appearance = 1
  276.       .Properties!Caption = sTmp & ":"
  277.       .Properties!Height = 255
  278.       .Properties!Index = i
  279.       .Properties!Left = 120
  280.       .Properties!Name = "lblLabels"
  281.       .Properties!Top = (i * 320) + 60
  282.       .Properties!Width = 1815
  283.     End With
  284.     If mrecRS.Fields(sTmp).Type = 1 Then
  285.       'true/false field
  286.       Set ctlNewControl = frmNewForm.ControlTemplates.Add("CheckBox")
  287.       With ctlNewControl
  288.         .Properties!Appearance = 1
  289.         .Properties!Caption = ""
  290.         .Properties!Height = 285
  291.         .Properties!Left = 2040
  292.         .Properties!Name = "chkField" & i
  293.         .Properties!Top = (i * 320) + 40
  294.         .Properties!Width = 3375
  295.         .Properties!DataSource = "Data1"
  296.         .Properties!DataField = sTmp
  297.       End With
  298.     ElseIf mrecRS.Fields(sTmp).Type = 11 Then
  299.       'picture field
  300.       Set ctlNewControl = frmNewForm.ControlTemplates.Add("OLE")
  301.       With ctlNewControl
  302.         .Properties!Height = 285
  303.         .Properties!Left = 2040
  304.         .Properties!Name = "oleField" & i
  305.         .Properties!OLETypeAllowed = 1
  306.         .Properties!Top = (i * 320) + 40
  307.         .Properties!Width = 3375
  308.         .Properties!DataSource = "Data1"
  309.         .Properties!DataField = sTmp
  310.       End With
  311.       SendKeys "{Esc}"
  312.       lstOLECtls.AddItem i
  313.     Else
  314.       Set ctlNewControl = frmNewForm.ControlTemplates.Add("TextBox")
  315.       With ctlNewControl
  316.         .Properties!Appearance = 1
  317.         .Properties!Left = 2040
  318.         .Properties!Name = "txtField" & i
  319.         .Properties!Text = ""
  320.         If mrecRS.Fields(sTmp).Type < 10 Then
  321.           'numeric or date
  322.           .Properties!Width = 1935
  323.         Else
  324.           'string or memo
  325.           .Properties!Width = 3375
  326.         End If
  327.         .Properties!DataSource = "Data1"
  328.         .Properties!DataField = sTmp
  329.         If mrecRS.Fields(sTmp).Type = 10 Then
  330.           .Properties!Height = 285
  331.           .Properties!Top = (i * 320) + 40
  332.           .Properties!MaxLength = mrecRS.Fields(sTmp).Size
  333.         ElseIf mrecRS.Fields(sTmp).Type = 12 Then
  334.           .Properties!Height = 310
  335.           .Properties!Top = (i * 320) + 30
  336.           .Properties!MultiLine = True
  337.           .Properties!ScrollBars = 2
  338.         Else
  339.           .Properties!Height = 285
  340.           .Properties!Top = (i * 320) + 40
  341.         End If
  342.       End With
  343.     End If
  344.   Next
  345.   nButtonTop = ctlNewControl.Properties!Top + 340
  346.   'add the data control and buttons
  347.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("Data")
  348.   With ctlNewControl
  349.     .Properties!Appearance = 1
  350.     .Properties!Align = 2
  351.     .Properties!Caption = ""
  352.     .Properties!DatabaseName = gdbCurrentDB.Name
  353.     .Properties!Connect = gdbCurrentDB.Connect
  354.     .Properties!RecordSource = cboRecordSource.Text
  355.   End With
  356.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("CommandButton")
  357.   With ctlNewControl
  358.     .Properties!Appearance = 1
  359.     .Properties!Caption = "&Add"
  360.     .Properties!Height = 300
  361.     .Properties!Left = 120
  362.     .Properties!Name = "cmdAdd"
  363.     .Properties!Top = nButtonTop
  364.     .Properties!Width = 975
  365.   End With
  366.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("CommandButton")
  367.   With ctlNewControl
  368.     .Properties!Appearance = 1
  369.     .Properties!Caption = "&Delete"
  370.     .Properties!Height = 300
  371.     .Properties!Left = 1200
  372.     .Properties!Name = "cmdDelete"
  373.     .Properties!Top = nButtonTop
  374.     .Properties!Width = 975
  375.   End With
  376.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("CommandButton")
  377.   With ctlNewControl
  378.     .Properties!Appearance = 1
  379.     .Properties!Caption = "&Refresh"
  380.     .Properties!Height = 300
  381.     .Properties!Left = 2280
  382.     .Properties!Name = "cmdRefresh"
  383.     .Properties!Top = nButtonTop
  384.     .Properties!Width = 975
  385.   End With
  386.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("CommandButton")
  387.   With ctlNewControl
  388.     .Properties!Appearance = 1
  389.     .Properties!Caption = "&Update"
  390.     .Properties!Height = 300
  391.     .Properties!Left = 3360
  392.     .Properties!Name = "cmdUpdate"
  393.     .Properties!Top = nButtonTop
  394.     .Properties!Width = 975
  395.   End With
  396.   Set ctlNewControl = frmNewForm.ControlTemplates.Add("CommandButton")
  397.   With ctlNewControl
  398.     .Properties!Appearance = 1
  399.     .Properties!Caption = "&Close"
  400.     .Properties!Height = 300
  401.     .Properties!Left = 4440
  402.     .Properties!Name = "cmdClose"
  403.     .Properties!Top = nButtonTop
  404.     .Properties!Width = 975
  405.   End With
  406.   'add the code to the form
  407.   Dim fh As Integer
  408.   fh = FreeFile
  409.   Open App.Path & "\DFD_FRM.MOD" For Output As fh
  410.   WriteFrmCode fh
  411.   Close fh
  412.   frmNewForm.InsertFile App.Path & "\DFD_FRM.MOD"
  413.   Kill App.Path & "\DFD_FRM.MOD"
  414.   'save the new form
  415.   gobjIDEAppInst.ActiveProject.SelectedComponents(0).SaveAs (gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM")
  416.   'set the form back to defaults
  417.   txtFormName.Text = ""
  418.   cboRecordSource.Text = ""
  419.   'try to set focus back to the form
  420.   Me.SetFocus
  421.   txtFormName.SetFocus
  422.   Exit Sub
  423. BuildErr:
  424.   MsgBox Error$
  425.   Exit Sub
  426. End Sub
  427. Sub cmdClose_Click()
  428.   Unload Me
  429. End Sub
  430. Private Sub cmdMoveFields_Click(Index As Integer)
  431.   Dim i As Integer
  432.   Select Case Index
  433.     Case 0
  434.       For i = 0 To lstFields.ListCount - 1
  435.         lstIncludedFields.AddItem lstFields.List(i)
  436.       Next
  437.       lstFields.Clear
  438.     Case 1
  439.       If lstFields.ListIndex = -1 Then Exit Sub
  440.       For i = lstFields.ListCount - 1 To 0 Step -1
  441.         If lstFields.Selected(i) = True Then
  442.           lstIncludedFields.AddItem lstFields.List(i)
  443.           lstFields.RemoveItem i
  444.         End If
  445.       Next
  446.     Case 2
  447.       If lstIncludedFields.ListIndex = -1 Then Exit Sub
  448.       For i = lstIncludedFields.ListCount - 1 To 0 Step -1
  449.         If lstIncludedFields.Selected(i) = True Then
  450.           lstFields.AddItem lstIncludedFields.List(i)
  451.           lstIncludedFields.RemoveItem i
  452.         End If
  453.       Next
  454.     Case 3
  455.       For i = 0 To lstIncludedFields.ListCount - 1
  456.         lstFields.AddItem lstIncludedFields.List(i)
  457.       Next
  458.       lstIncludedFields.Clear
  459.   End Select
  460. End Sub
  461. Sub Form_Load()
  462.   CenterMe Me, gnMDIFORM
  463.   GetTableList cboRecordSource, True, False, True
  464. End Sub
  465. Sub lstIncludedFields_DragDrop(Source As Control, x As Single, Y As Single)
  466.   Dim sTmp As String
  467.   Dim nPos As Integer
  468.   If Source = lstIncludedFields Then
  469.     If lstIncludedFields.ListIndex >= 0 Then
  470.       sTmp = lstIncludedFields.List(lstIncludedFields.ListIndex)
  471.       nPos = (Y / TextHeight(sTmp)) + lstIncludedFields.TopIndex
  472.       'check for the last item
  473.       If nPos > lstIncludedFields.ListCount Then
  474.         nPos = lstIncludedFields.ListCount
  475.       End If
  476.       lstIncludedFields.AddItem sTmp, nPos
  477.       If lstIncludedFields.ListIndex > nPos Then
  478.         lstIncludedFields.RemoveItem lstIncludedFields.ListIndex + 1
  479.       Else
  480.         lstIncludedFields.RemoveItem lstIncludedFields.ListIndex
  481.       End If
  482.     End If
  483.     Source.MousePointer = 0
  484.   End If
  485. End Sub
  486. Private Sub lstIncludedFields_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  487.   If Button = 1 Then lstIncludedFields.Drag
  488. End Sub
  489. Function StripFileName(rsFileName As String) As String
  490.   On Error Resume Next
  491.   Dim i As Integer
  492.   For i = Len(rsFileName) To 1 Step -1
  493.     If Mid(rsFileName, i, 1) = "\" Then
  494.       Exit For
  495.     End If
  496.   Next
  497.   StripFileName = Mid(rsFileName, 1, i - 1)
  498. End Function
  499. Sub BuildFormFile()
  500.   On Error GoTo BuildFErr
  501.   Dim i As Integer
  502.   Dim sTmp As String
  503.   Dim nNumFlds As Integer
  504.   Dim frmNewForm As Object
  505.   Dim ctlNewControl As Object
  506.   Dim nButtonTop As Integer
  507.   'create and open the file
  508.   Dim nFileHnd As Integer
  509.   nFileHnd = FreeFile
  510.   Open gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM" For Output As nFileHnd
  511.   Print #nFileHnd, "VERSION 4.00"
  512.   nNumFlds = lstIncludedFields.ListCount
  513.   lstOLECtls.Clear
  514.   Print #nFileHnd, "Begin VB.Form frm" & txtFormName.Text
  515.   'form height = 320 * numflds + 1260 for buttons and data control
  516.   'form width = 5640
  517.   Print #nFileHnd, "   Caption = """ & Left(mrecRS.Name, 32) & """"
  518.   Print #nFileHnd, "   Height       = " & 1115 + (nNumFlds * 320)
  519.   Print #nFileHnd, "   Left         = 2400"
  520.   Print #nFileHnd, "   Top          = 2040"
  521.   Print #nFileHnd, "   Width        = 5640"
  522.   'labels.left = 120, .width = 1815, .height = 255
  523.   'fields.left = 2040, .width = 3375, .height = 285
  524.   For i = 0 To nNumFlds - 1
  525.     sTmp = lstIncludedFields.List(i)
  526.     Print #nFileHnd, "   Begin VB.Label lblLabels"
  527.     Print #nFileHnd, "      Caption = """ & sTmp & ":"""
  528.     Print #nFileHnd, "      Height  = 255"
  529.     Print #nFileHnd, "      Index   = " & i
  530.     Print #nFileHnd, "      Left    = 120"
  531.     Print #nFileHnd, "      Top     = " & (i * 320) + 60
  532.     Print #nFileHnd, "      Width   = 1815"
  533.     Print #nFileHnd, "   End"
  534.     If mrecRS.Fields(sTmp).Type = 1 Then
  535.       'true/false field
  536.       Print #nFileHnd, "   Begin VB.CheckBox chkField" & i
  537.       Print #nFileHnd, "      DataField  = """ & sTmp & """"
  538.       Print #nFileHnd, "      DataSource = ""Data1"""
  539.       Print #nFileHnd, "      Height     = 285"
  540.       Print #nFileHnd, "      Index      = " & i
  541.       Print #nFileHnd, "      Left       = 2040"
  542.       Print #nFileHnd, "      Top        = " & (i * 320) + 40
  543.       Print #nFileHnd, "      Width      = 3375"
  544.       Print #nFileHnd, "   End"
  545.     ElseIf mrecRS.Fields(sTmp).Type = 11 Then
  546.       'picture field
  547.       Print #nFileHnd, "   Begin VB.OLE oleField" & i
  548.       Print #nFileHnd, "      DataField      = """ & sTmp & """"
  549.       Print #nFileHnd, "      DataSource     = ""Data1"""
  550.       Print #nFileHnd, "      Height         = 285"
  551.       Print #nFileHnd, "      Left           = 2040"
  552.       Print #nFileHnd, "      OLETypeAllowed = 1"
  553.       Print #nFileHnd, "      Top            = " & (i * 320) + 40
  554.       Print #nFileHnd, "      Width          = 3375"
  555.       Print #nFileHnd, "   End"
  556.       lstOLECtls.AddItem i
  557.     Else
  558.       Print #nFileHnd, "   Begin VB.TextBox txtField" & i
  559.       Print #nFileHnd, "      DataField  = """ & sTmp & """"
  560.       Print #nFileHnd, "      DataSource = ""Data1"""
  561.       If mrecRS.Fields(sTmp).Type = 12 Then
  562.         Print #nFileHnd, "      Height     = 310"
  563.       Else
  564.         Print #nFileHnd, "      Height     = 285"
  565.       End If
  566.       Print #nFileHnd, "      Index      = " & i
  567.       Print #nFileHnd, "      Left       = 2040"
  568.       If mrecRS.Fields(sTmp).Type = 10 Then
  569.         Print #nFileHnd, "      MaxLength   = " & mrecRS.Fields(sTmp).Size
  570.       End If
  571.       If mrecRS.Fields(sTmp).Type = 12 Then
  572.         Print #nFileHnd, "      MultiLine   = True"
  573.       End If
  574.       If mrecRS.Fields(sTmp).Type = 12 Then
  575.         Print #nFileHnd, "      ScrollBars  = 2"
  576.       End If
  577.       Print #nFileHnd, "      Top        = " & (i * 320) + 40
  578.       Print #nFileHnd, "      Text       = """""
  579.       If mrecRS.Fields(sTmp).Type < 10 Then
  580.         'numeric or date
  581.         Print #nFileHnd, "      Width      = 1935"
  582.       Else
  583.         'string or memo
  584.         Print #nFileHnd, "      Width      = 3375"
  585.       End If
  586.       Print #nFileHnd, "   End"
  587.     End If
  588.   Next
  589.   nButtonTop = (((i - 1) * 320) + 40) + 340
  590.   'add the data control and buttons
  591.   Print #nFileHnd, "   Begin VB.Data Data1"
  592.   Print #nFileHnd, "      Align        = 2"
  593.   Print #nFileHnd, "      Caption      = """""
  594.   Print #nFileHnd, "      Connect      = """ & gdbCurrentDB.Connect & """"
  595.   Print #nFileHnd, "      DatabaseName = """ & gdbCurrentDB.Name & """"
  596.   Print #nFileHnd, "      RecordSource = """ & cboRecordSource.Text & """"
  597.   Print #nFileHnd, "   End"
  598.   Print #nFileHnd, "   Begin VB.CommandButton cmdAdd"
  599.   Print #nFileHnd, "      Caption      = ""&Add"""
  600.   Print #nFileHnd, "      Height       = 300"
  601.   Print #nFileHnd, "      Left         = 120"
  602.   Print #nFileHnd, "      Top          = " & nButtonTop
  603.   Print #nFileHnd, "      Width        = 975"
  604.   Print #nFileHnd, "   End"
  605.   Print #nFileHnd, "   Begin VB.CommandButton cmdDelete"
  606.   Print #nFileHnd, "      Caption      = ""&Delete"""
  607.   Print #nFileHnd, "      Height       = 300"
  608.   Print #nFileHnd, "      Left         = 1200"
  609.   Print #nFileHnd, "      Top          = " & nButtonTop
  610.   Print #nFileHnd, "      Width        = 975"
  611.   Print #nFileHnd, "   End"
  612.   Print #nFileHnd, "   Begin VB.CommandButton cmdRefresh"
  613.   Print #nFileHnd, "      Caption      = ""&Refresh"""
  614.   Print #nFileHnd, "      Height       = 300"
  615.   Print #nFileHnd, "      Left         = 2280"
  616.   Print #nFileHnd, "      Top          = " & nButtonTop
  617.   Print #nFileHnd, "      Width        = 975"
  618.   Print #nFileHnd, "   End"
  619.   Print #nFileHnd, "   Begin VB.CommandButton cmdUpdate"
  620.   Print #nFileHnd, "      Caption      = ""&Update"""
  621.   Print #nFileHnd, "      Height       = 300"
  622.   Print #nFileHnd, "      Left         = 3360"
  623.   Print #nFileHnd, "      Top          = " & nButtonTop
  624.   Print #nFileHnd, "      Width        = 975"
  625.   Print #nFileHnd, "   End"
  626.   Print #nFileHnd, "   Begin VB.CommandButton cmdClose"
  627.   Print #nFileHnd, "      Caption      = ""&Close"""
  628.   Print #nFileHnd, "      Height       = 300"
  629.   Print #nFileHnd, "      Left         = 4440"
  630.   Print #nFileHnd, "      Top          = " & nButtonTop
  631.   Print #nFileHnd, "      Width        = 975"
  632.   Print #nFileHnd, "   End"
  633.   Print #nFileHnd, "End"
  634.   Print #nFileHnd, ""
  635.   Print #nFileHnd, "Attribute VB_Name = ""frm" & txtFormName.Text & """"
  636.   Print #nFileHnd, "Attribute VB_Creatable = False"
  637.   Print #nFileHnd, "Attribute VB_Exposed = False"
  638.   Print #nFileHnd, "Option Explicit"
  639.   Print #nFileHnd, ""
  640.   'add the code to the form
  641.   WriteFrmCode nFileHnd
  642.   Close nFileHnd
  643.   'add the new form to the project
  644.   gobjIDEAppInst.ActiveProject.AddFile gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM"
  645.   'set the form back to defaults
  646.   txtFormName.Text = ""
  647.   cboRecordSource.Text = ""
  648.   'try to set focus back to the form
  649.   Me.SetFocus
  650.   txtFormName.SetFocus
  651.   Exit Sub
  652. BuildFErr:
  653.   MsgBox Error$
  654.   Exit Sub
  655. End Sub
  656. Sub WriteFrmCode(fh As Integer)
  657.   On Error GoTo WCErr
  658.   Dim i As Integer
  659.   Print #fh, "Private Sub cmdAdd_Click()"
  660.   Print #fh, "  Data1.Recordset.AddNew"
  661.   Print #fh, "End Sub"
  662.   Print #fh, ""
  663.   Print #fh, "Private Sub cmdDelete_Click()"
  664.   Print #fh, "  'this may produce an error if you delete the last"
  665.   Print #fh, "  'record or the only record in the recordset"
  666.   Print #fh, "  Data1.Recordset.Delete"
  667.   Print #fh, "  Data1.Recordset.MoveNext"
  668.   Print #fh, "End Sub"
  669.   Print #fh, ""
  670.   Print #fh, "Private Sub cmdRefresh_Click()"
  671.   Print #fh, "  'this is really only needed for multi user apps"
  672.   Print #fh, "  Data1.Refresh"
  673.   Print #fh, "End Sub"
  674.   Print #fh, ""
  675.   Print #fh, "Private Sub cmdUpdate_Click()"
  676.   Print #fh, "  Data1.UpdateRecord"
  677.   Print #fh, "  Data1.Recordset.Bookmark = Data1.Recordset.LastModified"
  678.   Print #fh, "End Sub"
  679.   Print #fh, ""
  680.   Print #fh, "Private Sub cmdClose_Click()"
  681.   Print #fh, "  Unload Me"
  682.   Print #fh, "End Sub"
  683.   Print #fh, ""
  684.   Print #fh, "Private Sub Data1_Error(DataErr As Integer, Response As Integer)"
  685.   Print #fh, "  'This is where you would put error handling code"
  686.   Print #fh, "  'If you want to ignore errors, comment out the next line"
  687.   Print #fh, "  'If you want to trap them, add code here to handle them"
  688.   Print #fh, "  MsgBox ""Data error event hit err:"" & Error$(DataErr)"
  689.   Print #fh, "  Response = 0  'throw away the error"
  690.   Print #fh, "End Sub"
  691.   Print #fh, ""
  692.   Print #fh, "Private Sub Data1_Reposition()"
  693.   Print #fh, "  Screen.MousePointer = vbDefault"
  694.   Print #fh, "  On Error Resume Next"
  695.   Print #fh, "  'This will display the current record position"
  696.   Print #fh, "  'for dynasets and snapshots"
  697.   Print #fh, "  Data1.Caption = ""Record: "" & (Data1.Recordset.AbsolutePosition + 1)"
  698.   Print #fh, "  'for the table object you must set the index property when"
  699.   Print #fh, "  'the recordset gets created and use the following line"
  700.   Print #fh, "  'Data1.Caption = ""Record: "" & (Data1.Recordset.RecordCount * (Data1.Recordset.PercentPosition * 0.01)) + 1"
  701.   Print #fh, "End Sub"
  702.   Print #fh, ""
  703.   Print #fh, "Private Sub Data1_Validate(Action As Integer, Save As Integer)"
  704.   Print #fh, "  'This is where you put validation code"
  705.   Print #fh, "  'This event gets called when the following actions occur"
  706.   Print #fh, "  Select Case Action"
  707.   Print #fh, "    Case vbDataActionMoveFirst"
  708.   Print #fh, "    Case vbDataActionMovePrevious"
  709.   Print #fh, "    Case vbDataActionMoveNext"
  710.   Print #fh, "    Case vbDataActionMoveLast"
  711.   Print #fh, "    Case vbDataActionAddNew"
  712.   Print #fh, "    Case vbDataActionUpdate"
  713.   Print #fh, "    Case vbDataActionDelete"
  714.   Print #fh, "    Case vbDataActionFind"
  715.   Print #fh, "    Case vbDataActionBookMark"
  716.   Print #fh, "    Case vbDataActionClose"
  717.   Print #fh, "  End Select"
  718.   Print #fh, "  Screen.MousePointer = vbHourglass"
  719.   Print #fh, "End Sub"
  720.   Print #fh, ""
  721.   'write the code for the bound OLE client control(s)
  722.   For i = 0 To frmDFD.lstOLECtls.ListCount - 1
  723.     Print #fh, "Private Sub oleField" & frmDFD.lstOLECtls.List(i) & "_DblClick()"
  724.     Print #fh, "  'this is the way to get data into an empty ole control"
  725.     Print #fh, "  'and have it saved back to the table"
  726.     Print #fh, "  oleField" & frmDFD.lstOLECtls.List(i) & ".InsertObjDlg"
  727.     Print #fh, "End Sub"
  728.     Print #fh, ""
  729.   Next
  730.   Exit Sub
  731. WCErr:
  732.   MsgBox Error$
  733.   Exit Sub
  734. End Sub
  735.