VERSION 2.00
Begin Form frmAddAttrib 
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Add Attribute"
   ClientHeight    =   2010
   ClientLeft      =   3630
   ClientTop       =   5295
   ClientWidth     =   5790
   ControlBox      =   0   'False
   Height          =   2415
   Icon            =   ADDATTRB.FRX:0000
   KeyPreview      =   -1  'True
   Left            =   3570
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2010
   ScaleWidth      =   5790
   Top             =   4950
   Width           =   5910
   Begin TextBox txtDefValue 
      Height          =   285
      Left            =   1440
      TabIndex        =   2
      Top             =   840
      Width           =   4275
   End
   Begin TextBox txtPrompt 
      Height          =   285
      Left            =   1440
      TabIndex        =   3
      Top             =   1200
      Width           =   4275
   End
   Begin CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   375
      Left            =   3180
      TabIndex        =   5
      Top             =   1560
      Width           =   1035
   End
   Begin CommandButton cmdAdd 
      Caption         =   "&Add"
      Default         =   -1  'True
      Height          =   375
      Left            =   1800
      TabIndex        =   4
      Top             =   1560
      Width           =   1035
   End
   Begin TextBox txtValue 
      Height          =   285
      Left            =   1440
      TabIndex        =   1
      Top             =   480
      Width           =   4275
   End
   Begin TextBox txtName 
      Height          =   285
      Left            =   1440
      TabIndex        =   0
      Top             =   120
      Width           =   4275
   End
   Begin Label Label4 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "Default Value:"
      Height          =   195
      Left            =   60
      TabIndex        =   9
      Top             =   840
      Width           =   1335
   End
   Begin Label Label3 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "Prompt:"
      Height          =   195
      Left            =   540
      TabIndex        =   8
      Top             =   1200
      Width           =   855
   End
   Begin Label Label2 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "Value:"
      Height          =   195
      Left            =   660
      TabIndex        =   7
      Top             =   480
      Width           =   735
   End
   Begin Label Label1 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "Name:"
      Height          =   195
      Left            =   660
      TabIndex        =   6
      Top             =   120
      Width           =   735
   End
End
Option Explicit

Sub cmdAdd_Click ()
' Adds or writes an Attribute back to the database.  Remember, we're a dual
' purpose form here so check the global flag g_fEdit to see what mode we
' were invoked in.

    On Error GoTo lblAddErr

    Dim theAttrib As Object
    Dim Attribs As Object

    m_db.BeginTransaction

    If txtName.Text <> "" And Not (m_db Is Nothing) Then
        ' First we see if the Attribute still exists.

        Set Attribs = m_db.Attributes
        Set theAttrib = Attribs.Add(txtName.Text)

        If theAttrib Is Nothing Then
            MsgBox "Attribute no longer exists!"
        Else
            theAttrib.Value = txtValue.Text
            theAttrib.DefaultValue = txtDefValue.Text
            theAttrib.Prompt = txtPrompt.Text

            ' If we're in edit mode then we don't want to refresh the
            ' entire collection, thus we write the changes directly to our
            ' internal tables

            If g_fEdit Then
                m_strAttribs(IDX_VALUE, frmMain.ctlGrid.Row) = txtValue.Text
                m_strAttribs(IDX_DEFVALUE, frmMain.ctlGrid.Row) = txtDefValue.Text
                m_strAttribs(IDX_PROMPT, frmMain.ctlGrid.Row) = txtPrompt.Text
            End If
        End If
    End If

    ' Depending upon mode we refresh appropriately

    m_db.EndTransaction

    If g_fEdit Then
        RefreshGrid
    Else
        RefreshAll
    End If
    
    Unload frmAddAttrib
    
    Exit Sub

lblAddErr:
    m_db.EndTransaction
    MsgBox "Error adding new attribute"
    Exit Sub
End Sub

Sub cmdCancel_Click ()
    Unload frmAddAttrib
End Sub

Sub Form_KeyPress (KeyAscii As Integer)
    If 27 = KeyAscii Then cmdCancel_Click
End Sub

Sub Form_Load ()
    Dim theAttrib As ATTRIB

    SetWindowPos frmAddAttrib.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE

    Left = (Screen.Width / 2) - (Width / 2)
    Top = (Screen.Height / 2) - (Height / 2)

    If g_fEdit And GetCurrentAttrib(theAttrib) Then
        txtName.Enabled = False
        frmAddAttrib.Caption = "Edit Attribute"
        cmdAdd.Caption = "&OK"

        txtName.Text = theAttrib.strName
        txtValue.Text = theAttrib.strValue
        txtDefValue.Text = theAttrib.strDefValue
        txtPrompt.Text = theAttrib.strPrompt
    Else
        frmAddAttrib.Caption = "New Attribute"
        cmdAdd.Caption = "&Add"
    End If
End Sub

