944,012 Members | Top Members by Rank

Ad:
1

code to validate data in Access withOUT using messageboxes

by on Apr 22nd, 2005
This code uses field level validation to check for data in fields in an Access form, and instead of using message boxes (as the "Validation Rule" and "Validation Text" properties of a field (in the table design window) do, it turns the associated label and control (textbox/listbox/combobox) background color to RED, and then freezes the cursor on the field that requires attention
Visual Basic 4 / 5 / 6 Code Snippet (Toggle Plain Text)
  1. Private Sub txtZipCode_Exit(Cancel As Integer)
  2. Trim (txtZipCode)
  3. If IsNull(txtZipCode) Then
  4. Cancel = 1
  5. Else: Cancel = 0
  6. End If
  7. If Cancel = 1 Then
  8. txtZipCode.BackColor = vbRed
  9. lblZIPCode.ForeColor = vbRed
  10. txtZipCode.SetFocus
  11. Else
  12. txtZipCode.BackColor = vbWhite
  13. lblZIPCode.ForeColor = vbBlack
  14. txtEmailAddress.SetFocus
  15. End If
  16. End Sub
  17. ======================================================
  18. Use the "Exit" routine - you need the "Cancel" property of that routine to freeze the cursor on the field. Trim the field - that removes leading and trailing spaces (" " is not the same as "") - then you check for a null value...If the value is null, set the cancel (as integer) property to one...Otherwise set it to zero....If the cancel property is one, then (the tab was canceled) set the label and field control color properties (forecolor is the text color of the label, backcolor is the background color of the field) to red, and freeze the cursor...otherwise, set the background color (backcolor) of the field control to white, and the foreground color (forecolor) of the label to black...and allow a tab to the next field
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: code to split (and reconnect) an Access database (part 2)
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Anti-piracy systems.......





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC