Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

highlight specific fields if validation not met 1

Status
Not open for further replies.

pandapark

Technical User
Jan 29, 2003
92
GB
Hi

I have a form where several fields are mandatory (this also includes recordset checks for subforms to check at least one record in subform is completed)- when the user clicks commit to Database - if any of the checks aren't met it runs a CheckFields Function which returns false and tells the user they haven't completed the form correctly.
What I'd like is for the uncompleted field(s) forecolour to change colour or flash - I can think of a long-winded way to do this * but has anyone a nice generic solution?

* seperate each check for each field/recordset - if not met set the value to 1 else set it to 0 - then at the end run a big if statement where if value = 1 set the form fields forecolour to red for example

many thanks
jack
 
You may consider playing with the Tag property of your checked controls.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Not sure if this is the kind of thing you are asking for, but I use this function everywhere I verify data. I just put in the verification criteria and let it do its thing. I have left in a sample verification to help.

Code:
Private Function VerifyCriteria(errMsgs As Boolean) As Boolean
   Dim errStr As String, errTitle As String
   Dim errOpts
   Dim critFail As Boolean
   errTitle = "Error: Invalid Data"
   errOpts = vbOKOnly + vbInformation
   critFail = False
   
   If NZ(Title, "") = "" Then 'No value
      errStr = errStr & vbCrLf & "The Title cannot be empty."
      Title.BackColor = GlobalConst.gcBackColorYellow
      critFail = True
   ElseIf (Len(Title) > GlobalConst.gcMaxLenTitle) Then
      errStr = errStr & vbCrLf & "The Title must be less than " & _
               GlobalConst.gcMaxLenTitle & " characters."
      Title.BackColor = GlobalConst.gcBackColorYellow
      critFail = True
   Else 'All criteria passed
      Title.BackColor = GlobalConst.gcBackColorNormal
   End If
   
   If NZ(ProjDesc, "") = "" Then 'No value
      errStr = errStr & vbCrLf & "The Project Description cannot be empty."
      ProjDesc.BackColor = GlobalConst.gcBackColorYellow
      critFail = True
   ElseIf (Len(ProjDesc) > GlobalConst.gcMaxLenProjDesc) Then
      errStr = errStr & vbCrLf & "The Project Description must be less than " & _
               GlobalConst.gcMaxLenProjDesc & " characters."
      ProjDesc.BackColor = GlobalConst.gcBackColorYellow
      critFail = True
   Else 'All criteria passed
      ProjDesc.BackColor = GlobalConst.gcBackColorNormal
   End If
   
   If (critFail) Then
      If (errMsgs) Then
         MsgBox errStr, errOpts, errTitle
      End If
      VerifyCriteria = False
   Else
      VerifyCriteria = True
   End If
End Function
 
GlobalConst is a module in which I store my global constant values for use in all of my forms and other modules. I just store in the value of the color I want for failing or successful code. There is other verification code, but I repeat all criteria verification just before I save / update any record.
 
thanks axoliien and PHV
the function is great and the idea of tag properties is something I haven't used before
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top