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

  1. VERSION 4.00
  2. Begin VB.Form frmDFD 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Data Form Designer"
  5.    ClientHeight    =   5310
  6.    ClientLeft      =   1155
  7.    ClientTop       =   2505
  8.    ClientWidth     =   6135
  9.    Height          =   5715
  10.    Icon            =   "DFD.frx":0000
  11.    Left            =   1095
  12.    LinkTopic       =   "Form1"
  13.    LockControls    =   -1  'True
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   5310
  17.    ScaleWidth      =   6135
  18.    Top             =   2160
  19.    Width           =   6255
  20.    Begin VB.CheckBox chkOnScreen 
  21.       Caption         =   "On Screen"
  22.       Height          =   210
  23.       Left            =   810
  24.       TabIndex        =   8
  25.       Top             =   4515
  26.       Width           =   1875
  27.    End
  28.    Begin VB.ListBox lstOLECtls 
  29.       BeginProperty Font 
  30.          name            =   "MS Sans Serif"
  31.          charset         =   0
  32.          weight          =   700
  33.          size            =   8.25
  34.          underline       =   0   'False
  35.          italic          =   0   'False
  36.          strikethrough   =   0   'False
  37.       EndProperty
  38.       Height          =   615
  39.       Left            =   120
  40.       TabIndex        =   21
  41.       Top             =   4560
  42.       Visible         =   0   'False
  43.       Width           =   615
  44.    End
  45.    Begin VB.CommandButton cmdMoveFields 
  46.       Caption         =   "<<"
  47.       BeginProperty Font 
  48.          name            =   "MS Sans Serif"
  49.          charset         =   0
  50.          weight          =   700
  51.          size            =   8.25
  52.          underline       =   0   'False
  53.          italic          =   0   'False
  54.          strikethrough   =   0   'False
  55.       EndProperty
  56.       Height          =   375
  57.       Index           =   3
  58.       Left            =   2760
  59.       TabIndex        =   9
  60.       Top             =   4080
  61.       Width           =   495
  62.    End
  63.    Begin VB.CommandButton cmdMoveFields 
  64.       Caption         =   "<"
  65.       BeginProperty Font 
  66.          name            =   "MS Sans Serif"
  67.          charset         =   0
  68.          weight          =   700
  69.          size            =   8.25
  70.          underline       =   0   'False
  71.          italic          =   0   'False
  72.          strikethrough   =   0   'False
  73.       EndProperty
  74.       Height          =   375
  75.       Index           =   2
  76.       Left            =   2760
  77.       TabIndex        =   7
  78.       Top             =   3600
  79.       Width           =   495
  80.    End
  81.    Begin VB.CommandButton cmdMoveFields 
  82.       Caption         =   ">"
  83.       BeginProperty Font 
  84.          name            =   "MS Sans Serif"
  85.          charset         =   0
  86.          weight          =   700
  87.          size            =   8.25
  88.          underline       =   0   'False
  89.          italic          =   0   'False
  90.          strikethrough   =   0   'False
  91.       EndProperty
  92.       Height          =   375
  93.       Index           =   1
  94.       Left            =   2760
  95.       TabIndex        =   6
  96.       Top             =   3120
  97.       Width           =   495
  98.    End
  99.    Begin VB.CommandButton cmdMoveFields 
  100.       Caption         =   ">>"
  101.       BeginProperty Font 
  102.          name            =   "MS Sans Serif"
  103.          charset         =   0
  104.          weight          =   700
  105.          size            =   8.25
  106.          underline       =   0   'False
  107.          italic          =   0   'False
  108.          strikethrough   =   0   'False
  109.       EndProperty
  110.       Height          =   375
  111.       Index           =   0
  112.       Left            =   2760
  113.       TabIndex        =   5
  114.       Top             =   2640
  115.       Width           =   495
  116.    End
  117.    Begin VB.ListBox lstIncludedFields 
  118.       DragIcon        =   "DFD.frx":030A
  119.       Height          =   1785
  120.       Left            =   3360
  121.       MultiSelect     =   2  'Extended
  122.       TabIndex        =   4
  123.       Top             =   2640
  124.       Width           =   2655
  125.    End
  126.    Begin VB.CommandButton cmdBuildForm 
  127.       Caption         =   "&Build the Form"
  128.       Height          =   375
  129.       Left            =   720
  130.       TabIndex        =   10
  131.       Top             =   4800
  132.       Width           =   1695
  133.    End
  134.    Begin VB.ComboBox cboRecordSource 
  135.       Height          =   300
  136.       Left            =   1680
  137.       TabIndex        =   2
  138.       Top             =   1680
  139.       Width           =   4335
  140.    End
  141.    Begin VB.ListBox lstFields 
  142.       DragIcon        =   "DFD.frx":0614
  143.       Height          =   1785
  144.       Left            =   120
  145.       MultiSelect     =   2  'Extended
  146.       TabIndex        =   3
  147.       Top             =   2640
  148.       Width           =   2535
  149.    End
  150.    Begin VB.CommandButton cmdOpenDB 
  151.       Caption         =   "&Open Database"
  152.       Height          =   375
  153.       Left            =   2760
  154.       TabIndex        =   11
  155.       Top             =   1200
  156.       Width           =   1935
  157.    End
  158.    Begin VB.ComboBox cboConnect 
  159.       Height          =   300
  160.       ItemData        =   "DFD.frx":091E
  161.       Left            =   1680
  162.       List            =   "DFD.frx":0940
  163.       TabIndex        =   1
  164.       Top             =   480
  165.       Width           =   4335
  166.    End
  167.    Begin VB.TextBox txtFormName 
  168.       Height          =   285
  169.       Left            =   3240
  170.       MaxLength       =   8
  171.       TabIndex        =   0
  172.       Top             =   120
  173.       Width           =   1095
  174.    End
  175.    Begin VB.CommandButton cmdClose 
  176.       Caption         =   "&Close"
  177.       Height          =   375
  178.       Left            =   3600
  179.       TabIndex        =   12
  180.       Top             =   4800
  181.       Width           =   1695
  182.    End
  183.    Begin VB.Label lblDatabaseName 
  184.       Height          =   255
  185.       Left            =   1680
  186.       TabIndex        =   22
  187.       Top             =   855
  188.       Width           =   4335
  189.    End
  190.    Begin MSComDlg.CommonDialog dlgDBOpen 
  191.       Left            =   360
  192.       Top             =   1200
  193.       _Version        =   65536
  194.       _ExtentX        =   847
  195.       _ExtentY        =   847
  196.       _StockProps     =   0
  197.    End
  198.    Begin VB.Line Line1 
  199.       BorderWidth     =   3
  200.       X1              =   120
  201.       X2              =   6000
  202.       Y1              =   2280
  203.       Y2              =   2280
  204.    End
  205.    Begin VB.Label lblLabels 
  206.       Alignment       =   2  'Center
  207.       Caption         =   "Select a Table/QueryDef from the list or enter a SQL statement."
  208.       Height          =   195
  209.       Index           =   4
  210.       Left            =   120
  211.       TabIndex        =   20
  212.       Top             =   2040
  213.       Width           =   5925
  214.    End
  215.    Begin VB.Label lblLabels 
  216.       AutoSize        =   -1  'True
  217.       Caption         =   "Included Columns: "
  218.       Height          =   195
  219.       Index           =   10
  220.       Left            =   3360
  221.       TabIndex        =   19
  222.       Top             =   2400
  223.       Width           =   1350
  224.    End
  225.    Begin VB.Label lblLabels 
  226.       AutoSize        =   -1  'True
  227.       Caption         =   " Drag/Drop to Change Order "
  228.       Height          =   195
  229.       Index           =   7
  230.       Left            =   3360
  231.       TabIndex        =   18
  232.       Top             =   4500
  233.       Width           =   2070
  234.    End
  235.    Begin VB.Label lblLabels 
  236.       AutoSize        =   -1  'True
  237.       Caption         =   "RecordSource: "
  238.       Height          =   195
  239.       Index           =   6
  240.       Left            =   105
  241.       TabIndex        =   17
  242.       Top             =   1740
  243.       Width           =   1125
  244.    End
  245.    Begin VB.Label lblLabels 
  246.       AutoSize        =   -1  'True
  247.       Caption         =   "Available Columns: "
  248.       Height          =   195
  249.       Index           =   3
  250.       Left            =   120
  251.       TabIndex        =   16
  252.       Top             =   2400
  253.       Width           =   1380
  254.    End
  255.    Begin VB.Label lblLabels 
  256.       AutoSize        =   -1  'True
  257.       Caption         =   "Connect String: "
  258.       Height          =   195
  259.       Index           =   2
  260.       Left            =   105
  261.       TabIndex        =   15
  262.       Top             =   540
  263.       Width           =   1140
  264.    End
  265.    Begin VB.Label lblLabels 
  266.       AutoSize        =   -1  'True
  267.       Caption         =   "Database Name: "
  268.       Height          =   195
  269.       Index           =   1
  270.       Left            =   105
  271.       TabIndex        =   14
  272.       Top             =   900
  273.       Width           =   1245
  274.    End
  275.    Begin VB.Label lblLabels 
  276.       AutoSize        =   -1  'True
  277.       Caption         =   "Base Form Name (w/o Extension): "
  278.       Height          =   195
  279.       Index           =   0
  280.       Left            =   105
  281.       TabIndex        =   13
  282.       Top             =   180
  283.       Width           =   2460
  284.    End
  285. Attribute VB_Name = "frmDFD"
  286. Attribute VB_Creatable = False
  287. Attribute VB_Exposed = False
  288. Dim mdbCurrentDB As DATABASE
  289. Dim msDBName As String
  290. Dim mrecRS As Recordset
  291. Dim mnDataType As Integer
  292. 'constants used for the data type of the database
  293. Const gnDT_NONE = -1
  294. Const gnDT_ACCESS = 0
  295. Const gnDT_DBASEIV = 1
  296. Const gnDT_DBASEIII = 2
  297. Const gnDT_FOXPRO26 = 3
  298. Const gnDT_FOXPRO25 = 4
  299. Const gnDT_FOXPRO20 = 5
  300. Const gnDT_PARADOX4X = 6
  301. Const gnDT_PARADOX3X = 7
  302. Const gnDT_BTRIEVE = 8
  303. Const gnDT_ODBC = 9
  304. Private Sub cboConnect_Change()
  305.   msDBName = ""
  306.   mnDataType = gnDT_NONE
  307.   lblDatabaseName.Caption = msDBName
  308.   cboRecordSource.Clear
  309.   Set mrecRS = Nothing
  310.   lstFields.Clear
  311.   lstIncludedFields.Clear
  312. End Sub
  313. Private Sub cboConnect_Click()
  314.   Call cboConnect_Change
  315.   mnDataType = cboConnect.ListIndex
  316. End Sub
  317. Private Sub cboRecordSource_Change()
  318.   Set mrecRS = Nothing
  319.   lstFields.Clear
  320.   lstIncludedFields.Clear
  321. End Sub
  322. Private Sub cboRecordSource_Click()
  323.   Call cboRecordSource_LostFocus
  324. End Sub
  325. Private Sub cboRecordSource_LostFocus()
  326.   On Error GoTo RSErr
  327.   Dim i As Integer
  328.   Dim fld As Field
  329.   If Len(cboRecordSource.TEXT) = 0 Then Exit Sub
  330.   Screen.MousePointer = 11
  331.   'this code clears out the current field list
  332.   'and gets the new fields from the new recordset
  333.   If mrecRS Is Nothing Then
  334.     Set mrecRS = mdbCurrentDB.OpenRecordset(cboRecordSource.TEXT)
  335.     For Each fld In mrecRS.Fields
  336.       lstFields.AddItem fld.Name
  337.     Next
  338.   ElseIf mrecRS.Name <> cboRecordSource.TEXT Then
  339.     lstFields.Clear
  340.     lstIncludedFields.Clear
  341.     Set mrecRS = mdbCurrentDB.OpenRecordset(cboRecordSource.TEXT)
  342.     For Each fld In mrecRS.Fields
  343.       lstFields.AddItem fld.Name
  344.     Next
  345.   End If
  346.   Screen.MousePointer = 0
  347.   Exit Sub
  348. RSErr:
  349.   Screen.MousePointer = 0
  350.   MsgBox Error$
  351.   Exit Sub
  352. End Sub
  353. Sub cmdBuildForm_Click()
  354.   If Len(txtFormName.TEXT) = 0 Then
  355.     MsgBox "Form Name cannot be blank!", 16
  356.     txtFormName.SetFocus
  357.     Exit Sub
  358.   End If
  359.   If InStr(txtFormName.TEXT, " ") > 0 Then
  360.     MsgBox "Form Name cannot have spaces in it!", 16
  361.     txtFormName.SetFocus
  362.     Exit Sub
  363.   End If
  364.   If mdbCurrentDB Is Nothing Then
  365.     MsgBox "You must open a Database!", 16
  366.     Exit Sub
  367.   End If
  368.   If Len(cboRecordSource.TEXT) = 0 Then
  369.     MsgBox "You must enter a RecordSource!", 16
  370.     Exit Sub
  371.   End If
  372.   If lstIncludedFields.ListCount = 0 Then
  373.     MsgBox "You must include some Columns!", 16
  374.     Exit Sub
  375.   End If
  376.   If chkOnScreen.VALUE = vbChecked Then
  377.     BuildFormOnScreen
  378.   Else
  379.     BuildFormFile
  380.   End If
  381. End Sub
  382. Sub cmdClose_Click()
  383.   Unload Me
  384. End Sub
  385. Private Sub cmdMoveFields_Click(Index As Integer)
  386.   Dim i As Integer
  387.   Select Case Index
  388.     Case 0
  389.       For i = 0 To lstFields.ListCount - 1
  390.         lstIncludedFields.AddItem lstFields.List(i)
  391.       Next
  392.       lstFields.Clear
  393.     Case 1
  394.       If lstFields.ListIndex = -1 Then Exit Sub
  395.       For i = lstFields.ListCount - 1 To 0 Step -1
  396.         If lstFields.Selected(i) = True Then
  397.           lstIncludedFields.AddItem lstFields.List(i)
  398.           lstFields.RemoveItem i
  399.         End If
  400.       Next
  401.     Case 2
  402.       If lstIncludedFields.ListIndex = -1 Then Exit Sub
  403.       For i = lstIncludedFields.ListCount - 1 To 0 Step -1
  404.         If lstIncludedFields.Selected(i) = True Then
  405.           lstFields.AddItem lstIncludedFields.List(i)
  406.           lstIncludedFields.RemoveItem i
  407.         End If
  408.       Next
  409.     Case 3
  410.       For i = 0 To lstIncludedFields.ListCount - 1
  411.         lstFields.AddItem lstIncludedFields.List(i)
  412.       Next
  413.       lstIncludedFields.Clear
  414.   End Select
  415. End Sub
  416. Sub Form_Load()
  417.   'center it on the screen
  418.   Me.TOP = (Screen.Height - Me.Height) \ 2
  419.   Me.Left = (Screen.Width - Me.Width) \ 2
  420.   #If Win32 Then
  421.     chkOnScreen.VALUE = vbChecked
  422.     chkOnScreen.Visible = False
  423.   #End If
  424.   cboConnect.ListIndex = 0
  425. End Sub
  426. Sub lstIncludedFields_DragDrop(Source As Control, x As Single, Y As Single)
  427.   Dim sTmp As String
  428.   Dim nPos As Integer
  429.   If Source = lstIncludedFields Then
  430.     If lstIncludedFields.ListIndex >= 0 Then
  431.       sTmp = lstIncludedFields.List(lstIncludedFields.ListIndex)
  432.       nPos = (Y / TextHeight(sTmp)) + lstIncludedFields.TopIndex
  433.       'check for the last item
  434.       If nPos > lstIncludedFields.ListCount Then
  435.         nPos = lstIncludedFields.ListCount
  436.       End If
  437.       lstIncludedFields.AddItem sTmp, nPos
  438.       If lstIncludedFields.ListIndex > nPos Then
  439.         lstIncludedFields.RemoveItem lstIncludedFields.ListIndex + 1
  440.       Else
  441.         lstIncludedFields.RemoveItem lstIncludedFields.ListIndex
  442.       End If
  443.     End If
  444.     Source.MousePointer = 0
  445.   End If
  446. End Sub
  447. Private Sub cmdOpenDB_Click()
  448.   On Error GoTo OpenError
  449.   Dim sConnect As String
  450.   Dim sDatabaseName As String
  451.   Dim tdf As TableDef
  452.   Dim qdf As QueryDef
  453.   Select Case mnDataType
  454.     Case gnDT_ACCESS
  455.       dlgDBOpen.Filter = "Access DBs (*.mdb)|*.mdb|All Files (*.*)|*.*"
  456.       dlgDBOpen.DialogTitle = "Open MS Access Database"
  457.     Case gnDT_BTRIEVE
  458.       dlgDBOpen.Filter = "Btrieve DBs (FILE.DDF)|FILE.DDF"
  459.       dlgDBOpen.DialogTitle = "Open Btrieve Database"
  460.     Case gnDT_DBASEIII
  461.       dlgDBOpen.Filter = "dBASE III DBs (*.dbf)|*.dbf"
  462.       dlgDBOpen.DialogTitle = "Open dBASE III Database"
  463.     Case gnDT_DBASEIV
  464.       dlgDBOpen.Filter = "dBASE IV DBs (*.dbf)|*.dbf"
  465.       dlgDBOpen.DialogTitle = "Open dBASE IV Database"
  466.     Case gnDT_FOXPRO20
  467.       dlgDBOpen.Filter = "FoxPro DBs (*.dbf)|*.dbf"
  468.       dlgDBOpen.DialogTitle = "Open FoxPro 2.0 Database"
  469.     Case gnDT_FOXPRO25
  470.       dlgDBOpen.Filter = "FoxPro DBs (*.dbf)|*.dbf"
  471.       dlgDBOpen.DialogTitle = "Open FoxPro 2.5 Database"
  472.     Case gnDT_FOXPRO26
  473.       dlgDBOpen.Filter = "FoxPro DBs (*.dbf)|*.dbf"
  474.       dlgDBOpen.DialogTitle = "Open FoxPro 2.6 Database"
  475.     Case gnDT_PARADOX3X
  476.       dlgDBOpen.Filter = "Paradox DBs (*.db)|*.db"
  477.       dlgDBOpen.DialogTitle = "Open Paradox 3.X Database"
  478.     Case gnDT_PARADOX4X
  479.       dlgDBOpen.Filter = "Paradox DBs (*.db)|*.db"
  480.       dlgDBOpen.DialogTitle = "Open Paradox 4.X Database"
  481.     Case Else
  482.       If UCase(Left(cboConnect.TEXT, 4)) = "ODBC" Then
  483.         'default to ODBC
  484.         mnDataType = gnDT_ODBC
  485.       Else
  486.         Beep
  487.         MsgBox "Invalid Connect String!", 48
  488.         Exit Sub
  489.       End If
  490.   End Select
  491.   If mnDataType <> gnDT_ODBC Then
  492.     With dlgDBOpen
  493.       .FilterIndex = 1
  494.       .FileName = msDBName  '""
  495.       .CancelError = True
  496.       .Flags = &H4
  497.       .Action = 1
  498.     End With
  499.     msDBName = dlgDBOpen.FileName
  500.   Else
  501.     msDBName = ""
  502.   End If
  503.   lblDatabaseName.Caption = msDBName
  504.   cboRecordSource.Clear
  505.   Set mrecRS = Nothing
  506.   lstFields.Clear
  507.   lstIncludedFields.Clear
  508.   Me.Refresh       'repaint the form to get rid og the common dialog
  509.   Select Case mnDataType
  510.     Case gnDT_ACCESS
  511.       sConnect = ""
  512.       sDatabaseName = msDBName
  513.     Case gnDT_DBASEIII
  514.       sConnect = "dBASE III"
  515.       sDatabaseName = StripFileName(msDBName)
  516.     Case gnDT_DBASEIV
  517.       sConnect = "dBASE IV"
  518.       sDatabaseName = StripFileName(msDBName)
  519.     Case gnDT_FOXPRO20
  520.       sConnect = "FoxPro 2.0"
  521.       sDatabaseName = StripFileName(msDBName)
  522.     Case gnDT_FOXPRO25
  523.       sConnect = "FoxPro 2.5"
  524.       sDatabaseName = StripFileName(msDBName)
  525.     Case gnDT_PARADOX3X
  526.       sConnect = "Paradox 3.X"
  527.       sDatabaseName = StripFileName(msDBName)
  528.     Case gnDT_PARADOX4X
  529.       sConnect = "Paradox 4.X"
  530.       sDatabaseName = StripFileName(msDBName)
  531.     Case gnDT_BTRIEVE
  532.       sConnect = "Btrieve;"
  533.       sDatabaseName = msDBName
  534.     Case Else
  535.       sConnect = cboConnect.TEXT
  536.       sDatabaseName = msDBName
  537.   End Select
  538.   Screen.MousePointer = 11 'set the hourglass
  539.   Set mdbCurrentDB = OpenDatabase(sDatabaseName, False, True, sConnect)
  540.   'set the connect string for an ODBC datasource
  541.   If mnDataType = gnDT_ODBC Then
  542.     cboConnect.TEXT = mdbCurrentDB.Connect
  543.   End If
  544.   For Each tdf In mdbCurrentDB.TableDefs
  545.     If (tdf.Attributes And &H80000002) = 0 Then
  546.       cboRecordSource.AddItem tdf.Name
  547.     End If
  548.   Next
  549.   If mnDataType = gnDT_ACCESS Then
  550.     For Each qdf In mdbCurrentDB.QueryDefs
  551.       cboRecordSource.AddItem qdf.Name
  552.     Next
  553.   End If
  554.   cboRecordSource.ListIndex = 0
  555.   Screen.MousePointer = 0 'unset the hourglass
  556.   Exit Sub
  557. OpenError:
  558.   Screen.MousePointer = 0 'unset the hourglass
  559.   If Err <> 32755 Then     'check for common dialog cancelled
  560.     MsgBox Error
  561.   End If
  562.   Exit Sub
  563. End Sub
  564. Private Sub lstIncludedFields_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  565.   If Button = 1 Then lstIncludedFields.Drag
  566. End Sub
  567. Sub BuildFormOnScreen()
  568.   On Error GoTo BuildErr
  569.   Dim i As Integer
  570.   Dim sTmp As String
  571.   Dim nNumFlds As Integer
  572.   Dim frmNewForm As VBIDE.FormTemplate
  573.   Dim nButtonTop As Integer
  574.   Dim iHiddenLeft As Integer
  575.   nNumFlds = lstIncludedFields.ListCount
  576.   lstOLECtls.Clear
  577.   'create the new form
  578.   Set frmNewForm = gobjIDEAppInst.ActiveProject.AddFormTemplate()
  579.   'form height = 320 * numflds + 1260 for buttons and data control
  580.   'form width = 5640
  581.   With frmNewForm.Properties
  582.     .Item("Caption") = Left(mrecRS.Name, 32)
  583.     .Item("Height") = 1115 + (nNumFlds * 320)
  584.     .Item("Name") = "frm" & txtFormName.TEXT
  585.     .Item("Width") = 5640
  586.     .Item("Left") = 1050
  587.   End With
  588.   iHiddenLeft = -5640
  589.   'labels.left") = 120, .width") = 1815, .height = 255
  590.   'fields.left = 2040, .width = 3375, .height = 285
  591.   For i = 0 To nNumFlds - 1
  592.     sTmp = lstIncludedFields.List(i)
  593.     With frmNewForm.ControlTemplates.Add("Label").Properties
  594.       .Item("Left") = iHiddenLeft
  595.       .Item("Caption") = sTmp & ":"
  596.       .Item("Height") = 255
  597.       .Item("Index") = i
  598.       .Item("Name") = "lblLabels"
  599.       .Item("Top") = (i * 320) + 60
  600.       .Item("Width") = 1815
  601.       .Item("Left") = 120
  602.     End With
  603.     If mrecRS.Fields(sTmp).Type = 1 Then
  604.       'true/false field
  605.       With frmNewForm.ControlTemplates.Add("CheckBox").Properties
  606.         .Item("Left") = iHiddenLeft
  607.         .Item("Caption") = ""
  608.         .Item("Height") = 285
  609.         .Item("Index") = i
  610.         .Item("Name") = "chkFields"
  611.         .Item("Top") = (i * 320) + 40
  612.         .Item("Width") = 3375
  613.         .Item("DataSource") = "Data1"
  614.         .Item("DataField") = sTmp
  615.         .Item("Left") = 2040
  616.       End With
  617.     ElseIf mrecRS.Fields(sTmp).Type = 11 Then
  618.       'picture field
  619.       With frmNewForm.ControlTemplates.Add("OLE").Properties
  620.         .Item("Left") = iHiddenLeft
  621.         .Item("Height") = 285
  622.         .Item("Name") = "oleField" & i
  623.         .Item("OLETypeAllowed") = 1
  624.         .Item("Top") = (i * 320) + 40
  625.         .Item("Width") = 3375
  626.         .Item("DataSource") = "Data1"
  627.         .Item("DataField") = sTmp
  628.         .Item("Left") = 2040
  629.       End With
  630.       SendKeys "{Esc}"
  631.       lstOLECtls.AddItem i
  632.     Else
  633.       With frmNewForm.ControlTemplates.Add("TextBox").Properties
  634.         .Item("Left") = iHiddenLeft
  635.         .Item("Index") = i
  636.         .Item("Name") = "txtFields"
  637.         .Item("Text") = ""
  638.         If mrecRS.Fields(sTmp).Type < 10 Then
  639.           'numeric or date
  640.           .Item("Width") = 1935
  641.         Else
  642.           'string or memo
  643.           .Item("Width") = 3375
  644.         End If
  645.         .Item("DataSource") = "Data1"
  646.         .Item("DataField") = sTmp
  647.         If mrecRS.Fields(sTmp).Type = 10 Then
  648.           .Item("Height") = 285
  649.           .Item("Top") = (i * 320) + 40
  650.           .Item("MaxLength") = mrecRS.Fields(sTmp).Size
  651.         ElseIf mrecRS.Fields(sTmp).Type = 12 Then
  652.           .Item("Height") = 310
  653.           .Item("Top") = (i * 320) + 30
  654.           .Item("MultiLine") = True
  655.           .Item("ScrollBars") = 2
  656.         Else
  657.           .Item("Height") = 285
  658.           .Item("Top") = (i * 320) + 40
  659.         End If
  660.         .Item("Left") = 2040
  661.       End With
  662.     End If
  663.   Next
  664.   nButtonTop = i * 320 + 60 'ctlNewControl.Properties.Item("Top") + 340
  665.   'add the data control and buttons
  666.   With frmNewForm.ControlTemplates.Add("Data").Properties
  667.     .Item("Left") = iHiddenLeft
  668.     .Item("Caption") = ""
  669.     .Item("DatabaseName") = mdbCurrentDB.Name
  670.     .Item("Connect") = mdbCurrentDB.Connect
  671.     .Item("RecordSource") = cboRecordSource.TEXT
  672.     .Item("Align") = 2
  673.   End With
  674.   With frmNewForm.ControlTemplates.Add("CommandButton").Properties
  675.     .Item("Left") = iHiddenLeft
  676.     .Item("Caption") = "&Add"
  677.     .Item("Height") = 300
  678.     .Item("Name") = "cmdAdd"
  679.     .Item("Top") = nButtonTop
  680.     .Item("Width") = 975
  681.     .Item("Left") = 120
  682.   End With
  683.   With frmNewForm.ControlTemplates.Add("CommandButton").Properties
  684.     .Item("Left") = iHiddenLeft
  685.     .Item("Caption") = "&Delete"
  686.     .Item("Height") = 300
  687.     .Item("Name") = "cmdDelete"
  688.     .Item("Top") = nButtonTop
  689.     .Item("Width") = 975
  690.     .Item("Left") = 1200
  691.   End With
  692.   With frmNewForm.ControlTemplates.Add("CommandButton").Properties
  693.     .Item("Left") = iHiddenLeft
  694.     .Item("Caption") = "&Refresh"
  695.     .Item("Height") = 300
  696.     .Item("Name") = "cmdRefresh"
  697.     .Item("Top") = nButtonTop
  698.     .Item("Width") = 975
  699.     .Item("Left") = 2280
  700.   End With
  701.   With frmNewForm.ControlTemplates.Add("CommandButton").Properties
  702.     .Item("Left") = iHiddenLeft
  703.     .Item("Caption") = "&Update"
  704.     .Item("Height") = 300
  705.     .Item("Name") = "cmdUpdate"
  706.     .Item("Top") = nButtonTop
  707.     .Item("Width") = 975
  708.     .Item("Left") = 3360
  709.   End With
  710.   With frmNewForm.ControlTemplates.Add("CommandButton").Properties
  711.     .Item("Left") = iHiddenLeft
  712.     .Item("Caption") = "&Close"
  713.     .Item("Height") = 300
  714.     .Item("Name") = "cmdClose"
  715.     .Item("Top") = nButtonTop
  716.     .Item("Width") = 975
  717.     .Item("Left") = 4440
  718.   End With
  719.   'add the code to the form
  720.   Dim fh As Integer
  721.   fh = FreeFile
  722.   Open App.Path & "\DFD_FRM.MOD" For Output As fh
  723.   WriteFrmCode fh
  724.   Close fh
  725.   frmNewForm.InsertFile App.Path & "\DFD_FRM.MOD"
  726.   Kill App.Path & "\DFD_FRM.MOD"
  727.   'save the new form
  728.   gobjIDEAppInst.ActiveProject.SelectedComponents(0).SaveAs (gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM")
  729.   'set the form back to defaults
  730.   txtFormName.TEXT = ""
  731.   cboRecordSource.TEXT = ""
  732.   'try to set focus back to the form
  733.   Me.SetFocus
  734.   txtFormName.SetFocus
  735.   Exit Sub
  736. BuildErr:
  737.   MsgBox Error$
  738.   Exit Sub
  739. End Sub
  740. Sub BuildFormFile()
  741.   On Error GoTo BuildFErr
  742.   Dim i As Integer
  743.   Dim sTmp As String
  744.   Dim nNumFlds As Integer
  745.   Dim frmNewForm As Object
  746.   Dim ctlNewControl As Object
  747.   Dim nButtonTop As Integer
  748.   'create and open the file
  749.   Dim nFileHnd As Integer
  750.   nFileHnd = FreeFile
  751.   Open gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM" For Output As nFileHnd
  752.   Print #nFileHnd, "VERSION 4.00"
  753.   nNumFlds = lstIncludedFields.ListCount
  754.   lstOLECtls.Clear
  755.   Print #nFileHnd, "Begin VB.Form frm" & txtFormName.TEXT
  756.   'form height = 320 * numflds + 1260 for buttons and data control
  757.   'form width = 5640
  758.   Print #nFileHnd, "   Caption = """ & Left(mrecRS.Name, 32) & """"
  759.   Print #nFileHnd, "   Height       = " & 1115 + (nNumFlds * 320)
  760.   Print #nFileHnd, "   Left         = 2400"
  761.   Print #nFileHnd, "   Top          = 2040"
  762.   Print #nFileHnd, "   Width        = 5640"
  763.   'labels.left = 120, .width = 1815, .height = 255
  764.   'fields.left = 2040, .width = 3375, .height = 285
  765.   For i = 0 To nNumFlds - 1
  766.     sTmp = lstIncludedFields.List(i)
  767.     Print #nFileHnd, "   Begin VB.Label lblLabels"
  768.     Print #nFileHnd, "      Caption = """ & sTmp & ":"""
  769.     Print #nFileHnd, "      Height  = 255"
  770.     Print #nFileHnd, "      Index   = " & i
  771.     Print #nFileHnd, "      Left    = 120"
  772.     Print #nFileHnd, "      Top     = " & (i * 320) + 60
  773.     Print #nFileHnd, "      Width   = 1815"
  774.     Print #nFileHnd, "   End"
  775.     If mrecRS.Fields(sTmp).Type = 1 Then
  776.       'true/false field
  777.       Print #nFileHnd, "   Begin VB.CheckBox chkField" & i
  778.       Print #nFileHnd, "      DataField  = """ & sTmp & """"
  779.       Print #nFileHnd, "      DataSource = ""Data1"""
  780.       Print #nFileHnd, "      Height     = 285"
  781.       Print #nFileHnd, "      Index      = " & i
  782.       Print #nFileHnd, "      Left       = 2040"
  783.       Print #nFileHnd, "      Top        = " & (i * 320) + 40
  784.       Print #nFileHnd, "      Width      = 3375"
  785.       Print #nFileHnd, "   End"
  786.     ElseIf mrecRS.Fields(sTmp).Type = 11 Then
  787.       'picture field
  788.       Print #nFileHnd, "   Begin VB.OLE oleField" & i
  789.       Print #nFileHnd, "      DataField      = """ & sTmp & """"
  790.       Print #nFileHnd, "      DataSource     = ""Data1"""
  791.       Print #nFileHnd, "      Height         = 285"
  792.       Print #nFileHnd, "      Left           = 2040"
  793.       Print #nFileHnd, "      OLETypeAllowed = 1"
  794.       Print #nFileHnd, "      Top            = " & (i * 320) + 40
  795.       Print #nFileHnd, "      Width          = 3375"
  796.       Print #nFileHnd, "   End"
  797.       lstOLECtls.AddItem i
  798.     Else
  799.       Print #nFileHnd, "   Begin VB.TextBox txtField" & i
  800.       Print #nFileHnd, "      DataField  = """ & sTmp & """"
  801.       Print #nFileHnd, "      DataSource = ""Data1"""
  802.       If mrecRS.Fields(sTmp).Type = 12 Then
  803.         Print #nFileHnd, "      Height     = 310"
  804.       Else
  805.         Print #nFileHnd, "      Height     = 285"
  806.       End If
  807.       Print #nFileHnd, "      Index      = " & i
  808.       Print #nFileHnd, "      Left       = 2040"
  809.       If mrecRS.Fields(sTmp).Type = 10 Then
  810.         Print #nFileHnd, "      MaxLength   = " & mrecRS.Fields(sTmp).Size
  811.       End If
  812.       If mrecRS.Fields(sTmp).Type = 12 Then
  813.         Print #nFileHnd, "      MultiLine   = True"
  814.       End If
  815.       If mrecRS.Fields(sTmp).Type = 12 Then
  816.         Print #nFileHnd, "      ScrollBars  = 2"
  817.       End If
  818.       Print #nFileHnd, "      Top        = " & (i * 320) + 40
  819.       Print #nFileHnd, "      Text       = """""
  820.       If mrecRS.Fields(sTmp).Type < 10 Then
  821.         'numeric or date
  822.         Print #nFileHnd, "      Width      = 1935"
  823.       Else
  824.         'string or memo
  825.         Print #nFileHnd, "      Width      = 3375"
  826.       End If
  827.       Print #nFileHnd, "   End"
  828.     End If
  829.   Next
  830.   nButtonTop = (((i - 1) * 320) + 40) + 340
  831.   'add the data control and buttons
  832.   Print #nFileHnd, "   Begin VB.Data Data1"
  833.   Print #nFileHnd, "      Align        = 2"
  834.   Print #nFileHnd, "      Caption      = """""
  835.   Print #nFileHnd, "      Connect      = """ & mdbCurrentDB.Connect & """"
  836.   Print #nFileHnd, "      DatabaseName = """ & mdbCurrentDB.Name & """"
  837.   Print #nFileHnd, "      RecordSource = """ & cboRecordSource.TEXT & """"
  838.   Print #nFileHnd, "   End"
  839.   Print #nFileHnd, "   Begin VB.CommandButton cmdAdd"
  840.   Print #nFileHnd, "      Caption      = ""&Add"""
  841.   Print #nFileHnd, "      Height       = 300"
  842.   Print #nFileHnd, "      Left         = 120"
  843.   Print #nFileHnd, "      Top          = " & nButtonTop
  844.   Print #nFileHnd, "      Width        = 975"
  845.   Print #nFileHnd, "   End"
  846.   Print #nFileHnd, "   Begin VB.CommandButton cmdDelete"
  847.   Print #nFileHnd, "      Caption      = ""&Delete"""
  848.   Print #nFileHnd, "      Height       = 300"
  849.   Print #nFileHnd, "      Left         = 1200"
  850.   Print #nFileHnd, "      Top          = " & nButtonTop
  851.   Print #nFileHnd, "      Width        = 975"
  852.   Print #nFileHnd, "   End"
  853.   Print #nFileHnd, "   Begin VB.CommandButton cmdRefresh"
  854.   Print #nFileHnd, "      Caption      = ""&Refresh"""
  855.   Print #nFileHnd, "      Height       = 300"
  856.   Print #nFileHnd, "      Left         = 2280"
  857.   Print #nFileHnd, "      Top          = " & nButtonTop
  858.   Print #nFileHnd, "      Width        = 975"
  859.   Print #nFileHnd, "   End"
  860.   Print #nFileHnd, "   Begin VB.CommandButton cmdUpdate"
  861.   Print #nFileHnd, "      Caption      = ""&Update"""
  862.   Print #nFileHnd, "      Height       = 300"
  863.   Print #nFileHnd, "      Left         = 3360"
  864.   Print #nFileHnd, "      Top          = " & nButtonTop
  865.   Print #nFileHnd, "      Width        = 975"
  866.   Print #nFileHnd, "   End"
  867.   Print #nFileHnd, "   Begin VB.CommandButton cmdClose"
  868.   Print #nFileHnd, "      Caption      = ""&Close"""
  869.   Print #nFileHnd, "      Height       = 300"
  870.   Print #nFileHnd, "      Left         = 4440"
  871.   Print #nFileHnd, "      Top          = " & nButtonTop
  872.   Print #nFileHnd, "      Width        = 975"
  873.   Print #nFileHnd, "   End"
  874.   Print #nFileHnd, "End"
  875.   Print #nFileHnd, ""
  876.   Print #nFileHnd, "Attribute VB_Name = ""frm" & txtFormName.TEXT & """"
  877.   Print #nFileHnd, "Attribute VB_Creatable = False"
  878.   Print #nFileHnd, "Attribute VB_Exposed = False"
  879.   Print #nFileHnd, "Option Explicit"
  880.   Print #nFileHnd, ""
  881.   'add the code to the form
  882.   WriteFrmCode nFileHnd
  883.   Close nFileHnd
  884.   'add the new form to the project
  885.   gobjIDEAppInst.ActiveProject.AddFile gobjIDEAppInst.LastUsedPath & "\" & txtFormName & ".FRM"
  886.   'set the form back to defaults
  887.   txtFormName.TEXT = ""
  888.   cboRecordSource.TEXT = ""
  889.   'try to set focus back to the form
  890.   Me.SetFocus
  891.   txtFormName.SetFocus
  892.   Exit Sub
  893. BuildFErr:
  894.   MsgBox Error$
  895.   Exit Sub
  896. End Sub
  897.