| | |
code to validate data in Access withOUT using messageboxes
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
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
Private Sub txtZipCode_Exit(Cancel As Integer) Trim (txtZipCode) If IsNull(txtZipCode) Then Cancel = 1 Else: Cancel = 0 End If If Cancel = 1 Then txtZipCode.BackColor = vbRed lblZIPCode.ForeColor = vbRed txtZipCode.SetFocus Else txtZipCode.BackColor = vbWhite lblZIPCode.ForeColor = vbBlack txtEmailAddress.SetFocus End If End Sub ====================================================== 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
Similar Threads
- MS Access data to Excel. (Java code). (Java)
- Funny / sarcastic windows messageboxes (Geeks' Lounge)
- How can i access data from MS Access using VB6 (I need the connection code) (Visual Basic 4 / 5 / 6)
- Vb.net source code to access data from Access Database (Visual Basic 4 / 5 / 6)
- vb.net code to access data from Access Database (VB.NET)
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window



