home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form frmEmployees
- BackColor = &H00FFFFFF&
- Caption = "Employee Records"
- ClientHeight = 3495
- ClientLeft = 1830
- ClientTop = 1620
- ClientWidth = 5775
- Height = 3900
- Left = 1770
- LinkTopic = "Form1"
- ScaleHeight = 3495
- ScaleWidth = 5775
- Top = 1275
- Width = 5895
- Begin ComboBox cbPosition
- BackColor = &H00C0C0C0&
- Height = 300
- Left = 2400
- TabIndex = 7
- Text = " "
- Top = 1675
- Width = 3105
- End
- Begin MaskEdBox tbSSN
- BackColor = &H00C0C0C0&
- DataField = "SSN"
- DataSource = "Data1"
- Format = "###-##-####"
- Height = 285
- Left = 2400
- MousePointer = 3 'I-Beam
- PromptChar = "_"
- PromptInclude = 0 'False
- TabIndex = 5
- Top = 1175
- Width = 1400
- End
- Begin CheckBox Check1
- Alignment = 1 'Right Justify
- Caption = "&Active:"
- DataField = "Active"
- DataSource = "Data1"
- Height = 225
- Left = 1350
- TabIndex = 8
- Top = 2115
- Width = 1260
- End
- Begin TextBox tbLName
- BackColor = &H00C0C0C0&
- DataField = "Last Name"
- DataSource = "Data1"
- Height = 285
- Left = 2415
- MaxLength = 15
- MousePointer = 3 'I-Beam
- TabIndex = 3
- Text = " "
- Top = 675
- Width = 1875
- End
- Begin TextBox tbFName
- BackColor = &H00C0C0C0&
- DataField = "First Name"
- DataSource = "Data1"
- Height = 285
- Left = 2400
- MaxLength = 15
- MousePointer = 3 'I-Beam
- TabIndex = 1
- Text = " "
- Top = 175
- Width = 1875
- End
- Begin PictureBox picCommand
- Height = 525
- Index = 0
- Left = 0
- ScaleHeight = 495
- ScaleWidth = 5775
- TabIndex = 9
- Top = 2700
- Width = 5800
- Begin CommandButton Command1
- Caption = "E&xit Program"
- Height = 330
- Left = 3000
- TabIndex = 11
- Top = 75
- Width = 1400
- End
- Begin CommandButton cmdedit
- Caption = "&Edit"
- Height = 330
- Left = 1400
- TabIndex = 10
- Top = 75
- Width = 1400
- End
- End
- Begin Data Data1
- BackColor = &H00C0C0C0&
- Caption = "Employees"
- Connect = ""
- DatabaseName = "C:\VB\EMPLOYEE.MDB"
- Exclusive = 0 'False
- Height = 300
- Left = 0
- Options = 0
- ReadOnly = 0 'False
- RecordSource = "Employees"
- Top = 3220
- Width = 5800
- End
- Begin PictureBox picCommand
- Height = 525
- Index = 1
- Left = 0
- ScaleHeight = 495
- ScaleWidth = 5775
- TabIndex = 13
- Top = 2700
- Visible = 0 'False
- Width = 5800
- Begin CommandButton cmdSave
- Caption = "&Save"
- Default = -1 'True
- Height = 330
- Left = 1400
- TabIndex = 12
- Top = 75
- Width = 1400
- End
- Begin CommandButton cmdCancel
- Cancel = -1 'True
- Caption = "&Cancel"
- Height = 330
- Left = 3000
- TabIndex = 14
- Top = 75
- Width = 1400
- End
- End
- Begin Label lblFields
- Alignment = 1 'Right Justify
- BackStyle = 0 'Transparent
- Caption = "&Position:"
- Height = 210
- Index = 3
- Left = 195
- TabIndex = 6
- Top = 1700
- Width = 1800
- End
- Begin Label lblFields
- Alignment = 1 'Right Justify
- BackStyle = 0 'Transparent
- Caption = "&Soc. Sec. No.:"
- Height = 210
- Index = 2
- Left = 195
- TabIndex = 4
- Top = 1200
- Width = 1800
- End
- Begin Label lblFields
- Alignment = 1 'Right Justify
- BackStyle = 0 'Transparent
- Caption = "&Last Name:"
- Height = 210
- Index = 1
- Left = 195
- TabIndex = 2
- Top = 700
- Width = 1800
- End
- Begin Label lblFields
- Alignment = 1 'Right Justify
- BackStyle = 0 'Transparent
- Caption = "&First Name:"
- Height = 210
- Index = 0
- Left = 195
- TabIndex = 0
- Top = 200
- Width = 1800
- End
- '-----------------------------------------------------
- ' Copyright (c) 1994 by Barth Riley
- ' Project Name: Edit Data Demonstration
- ' Description: Implements Edit button and
- ' read-only controls with a
- ' Data Control
- ' Author: Barth Riley
- ' Copyright date: Jan 29th, 1994
- ' Version: 1.0
- ' Project file: EDITDATA.MAK
- ' Number of forms: 1
- ' Number of modules: 1
- '-------------------------------------------------
- '---Dim Variables
- Dim fEdit As Integer ' Edit mode flag
- Dim fLoading As Integer ' True when a new rec. is loaded
- Sub cbPosition_DropDown ()
- If Not fEdit Then
- ' Temporarily disable the control
- Beep
- cbPosition.SelLength = 0
- cbPosition.Enabled = False
- cbPosition.Enabled = True
- End If
- End Sub
- Sub cbPosition_GotFocus ()
- If fEdit Then
- cbPosition.SelStart = 0
- cbPosition.SelLength = Len(cbPosition.Text)
- End If
- End Sub
- Sub cbPosition_KeyDown (KeyCode As Integer, Shift As Integer)
- If Not fEdit Then
- Beep
- KeyCode = 0
- End If
- End Sub
- Sub cbPosition_KeyPress (KeyAscii As Integer)
- If Not fEdit Then
- Beep
- KeyAscii = 0
- End If
- End Sub
- Sub cbPosition_LostFocus ()
- cbPosition.SelLength = 0
- End Sub
- Sub Check1_Click ()
- If fEdit Or fLoading Then
- Else
- '-----------------------------------------------
- ' The Data control will intialize
- ' the values of all bound controls
- ' prior to the Form_Load event. Hence
- ' both fEdit and fLoading will be False
- ' when the Check1 control is initialized.
- ' It will "appear" therefore that the user
- ' is trying to alter the value of the ckeck box
- ' when not in edit mode. To overcome this problem,
- ' I've used theTag property of the control to
- ' indicate whether the control has been
- ' initialized: If it has no value, then it
- ' is set to "Loading". Otherwise, a warning
- ' beep is sounded.
- '---------------------------------------------------
- If Check1.Tag = "" Then
- Check1.Tag = "Loaded"
- Else
- Beep
- End If
- Check1.Value = (Data1.Recordset("Active") * -1)
- End If
- End Sub
- Sub cmdCancel_Click ()
- Data1.UpdateControls ' Abandon changes to the rec.
- EnableCtls False ' Back to read-only mode
- End Sub
- Sub cmdEdit_Click ()
- EnableCtls True ' Allow edits
- End Sub
- Sub cmdSave_Click ()
- tbSSN.PromptInclude = True
- ' Update unbound controls
- Data1.Recordset("Position") = cbPosition.ListIndex + 1
- Data1.Recordset.Update
- EnableCtls False ' Back to read-only mode
- End Sub
- Sub Command1_Click ()
- Data1.Recordset.Close
- End
- End Sub
- Sub Data1_Reposition ()
- tbSSN.Mask = tbSSN.Text ' Set Mask to field value
- ' Set unbound controls
- cbPosition.ListIndex = Data1.Recordset("Position") - 1
- fLoading = False
- End Sub
- Sub Data1_Validate (Action As Integer, Save As Integer)
- If Action >= 1 And Action <= 4 Then
- ' User moving to a new record
- If fEdit Then
- ' We want to prevent the user from moving to
- ' a new record when s/he is editing the
- ' current record.
- Action = 0 ' Cancel move operation
- Save = 0
- Else
- fLoading = True ' allow controls to be updated
- tbSSN.Mask = "###-##-####"
- End If
- End If
- End Sub
- Sub EnableCtls (ByVal fEditOn As Integer)
- ' Set the text box controls to the appropriate
- ' edit mode
- fEdit = fEditOn
- SetTBReadOnly tbFName, Not fEditOn
- SetTBReadOnly tbLName, Not fEditOn
- If fEditOn Then
- ' Reset the Mask and text properties for tbSSN
- tbSSN.PromptInclude = False
- szMask = tbSSN.Mask
- tbSSN.Mask = ""
- tbSSN.Mask = "###-##-####"
- Data1.Caption = "Employee Records [Edit Mode]"
- tbFName.SetFocus
- Else
- tbSSN.Mask = ""
- tbSSN.Mask = tbSSN.Text
- tbSSN.PromptInclude = True
- Data1.Caption = "Employee Records [Read-Only]"
- End If
- ' Set the TabStop values...
- tbFName.TabStop = fEditOn
- tbLName.TabStop = fEditOn
- tbSSN.TabStop = fEditOn
- cbPosition.TabStop = fEditOn
- Check1.TabStop = fEditOn
- ' Make the appropriate command button group visible
- picCommand(0).Visible = Not fEditOn
- picCommand(1).Visible = fEditOn
- ' Set the default and cancel properties for
- ' each set of command buttons
- cmdEdit.Default = Not fEditOn
- cmdSave.Default = fEditOn
- cmdCancel.Cancel = fEditOn
- If fEdit Then Data1.Recordset.Edit
- '---End of code
- End Sub
- Sub Form_Load ()
- fLoading = True
- cbPosition.AddItem "Accountant"
- cbPosition.AddItem "Consultant"
- cbPosition.AddItem "Documentation Proofreader"
- cbPosition.AddItem "Head Honcho"
- cbPosition.AddItem "Project Manager"
- cbPosition.AddItem "Programmer"
- cbPosition.AddItem "Systems Analyst"
- cbPosition.AddItem "Technical Writer"
- Data1.Caption = "Employee List [Read-only]"
- EnableCtls False
- fLoading = False
- End Sub
- Sub tbFName_GotFocus ()
- If fEdit Then
- tbFName.SelStart = 0
- tbFName.SelLength = Len(tbFName.Text)
- End If
- End Sub
- Sub tbFName_KeyDown (KeyCode As Integer, Shift As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbFName_KeyPress (KeyAscii As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbFName_LostFocus ()
- tbFName.SelLength = 0
- End Sub
- Sub tbLName_GotFocus ()
- If fEdit Then
- tbLName.SelStart = 0
- tbLName.SelLength = Len(tbLName.Text)
- End If
- End Sub
- Sub tbLName_KeyDown (KeyCode As Integer, Shift As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbLName_KeyPress (KeyAscii As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbLName_LostFocus ()
- tbLName.SelLength = 0
- End Sub
- Sub tbSSN_GotFocus ()
- If fEdit Then
- tbSSN.SelStart = 0
- tbSSN.SelLength = 11
- End If
- End Sub
- Sub tbSSN_KeyDown (KeyCode As Integer, Shift As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbSSN_KeyPress (KeyAscii As Integer)
- If Not fEdit Then Beep
- End Sub
- Sub tbSSN_LostFocus ()
- tbSSN.SelLength = 0
- End Sub
-