Click to go home

This is the contact info form




Option Explicit
Public intContactID As Integer

Private Sub cmdCancel_Click() Unload Me End Sub
Private Sub cmdUpdate_Click() ' Verify that name fields are not empty If txtFirst.Text = "" Then MsgBox "You must provide a first name.", , "First Name" txtFirst.SetFocus Exit Sub ElseIf txtLast.Text = "" Then MsgBox "You must provide a last name.", , "Last Name" txtLast.SetFocus Exit Sub End If If Me.Caption = "Add new Contact" Then ' Insert values from text boxes into new record frmMain.cnDatabase.Execute "INSERT INTO Contacts(ContactId,LastName,FirstName,Phone,Fax,Email,Address,City,Province,PostalCode) " & _ "VALUES ('" & frmContacts.ContactID & "', '" & txtLast.Text & "', '" & txtFirst.Text & "', '" & mskPhone.Text & "', '" & mskFax.Text & "', '" & txtEmail.Text & "', '" & txtAddress.Text & "', '" & txtCity.Text & "', '" & cboProvince.Text & "', '" & txtPostal.Text & "')" ' Update and re-populate list box frmContacts.FillList Unload Me Else If MsgBox("Are you sure you want to make these permanent changes to the database?", vbYesNo + vbDefaultButton2, "Update Changes") = vbNo Then Exit Sub ' Insert values from text boxes into current record frmMain.cnDatabase.Execute "UPDATE Contacts " & _ "SET LastName = '" & txtLast.Text & "', FirstName = '" & txtFirst.Text & "', Phone = '" & mskPhone.Text & "', Fax = '" & mskFax.Text & "', Email = '" & txtEmail.Text & "', Address = '" & txtAddress.Text & "', City = '" & txtCity.Text & " ', Province = '" & cboProvince.Text & "', PostalCode = '" & txtPostal.Text & "'" & _ "WHERE ContactId = " & intContactID & "" ' Update and re-populate list box frmContacts.FillList Unload Me End If End Sub
Private Sub mskFax_Validate(Cancel As Boolean) ' Verify fax number is 7 digits If Len(mskFax.ClipText) >= 1 And Len(mskFax.ClipText) < 7 Then MsgBox "This field must contain 7 digits.", , "Fax" Cancel = True mskFax.SetFocus End If End Sub
Private Sub mskPhone_Validate(Cancel As Boolean) ' Verify phone number is 7 digits If Len(mskPhone.ClipText) >= 1 And Len(mskPhone.ClipText) < 7 Then MsgBox "This field must contain 7 digits.", , "Phone" Cancel = True mskPhone.SetFocus End If End Sub
Private Sub txtCity_KeyPress(KeyAscii As Integer) ' Ensure only letters, space, and backspace are entered If Chr(KeyAscii) < "A" And KeyAscii <> 32 And KeyAscii <> 8 Or Chr(KeyAscii) > "z" Or KeyAscii > 90 And KeyAscii < 97 Then KeyAscii = 0 Beep End If End Sub
Private Sub txtFirst_KeyPress(KeyAscii As Integer) ' Ensure only letters, space, and backspace are entered If Chr(KeyAscii) < "A" And KeyAscii <> 32 And KeyAscii <> 8 Or Chr(KeyAscii) > "z" Or KeyAscii > 90 And KeyAscii < 97 Then KeyAscii = 0 Beep End If End Sub
Private Sub txtFirst_Validate(Cancel As Boolean) ' Verify first name text is not empty If txtFirst.Text = "" Then MsgBox "This field cannot be empty.", , "" & lblFirst.Caption & "" Cancel = True End If End Sub
Private Sub txtLast_KeyPress(KeyAscii As Integer) ' Ensure only letters, space, and backspace are entered If Chr(KeyAscii) < "A" And KeyAscii <> 32 And KeyAscii <> 8 Or Chr(KeyAscii) > "z" Or KeyAscii > 90 And KeyAscii < 97 Then KeyAscii = 0 Beep End If End Sub
Private Sub txtLast_Validate(Cancel As Boolean) ' Verify last name text is not empty If txtLast.Text = "" Then MsgBox "This field cannot be empty.", , "" & lblLast.Caption & "" Cancel = True End If End Sub
Private Sub txtPostal_KeyPress(KeyAscii As Integer) ' Ensure postal code is uppercase KeyAscii = Asc(UCase(Chr(KeyAscii))) End Sub
Private Sub txtPostal_Validate(Cancel As Boolean) ' Esure that postal code is not empty and contains 6 characters If Len(txtPostal.Text) >= 1 And Len(txtPostal.Text) < txtPostal.MaxLength Then MsgBox "This field must have 6 characters.", , "" & lblPostal.Caption & "" Cancel = True End If End Sub
Next Page - Event Scheduler

Jump to:
Main  |   Contact Maintenance  |   Completed Events  |   Event Reminder

Go to top