Results 1 to 4 of 4
  1. #1
    LindaRuble is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012

    Highlight "Text Field" or "Check Box" conditionally when another field selected


    I would like to highlight an empty field when an item from a drop-down combo box has been selected. I would like this behavior only when the user tries to move away from the current record set or try to save the current record before filling the required field. I would also like a pop-up message to come up to notify that the user must fill in the highlighted fields. When the fields are filled in, I want the field background color to go back to white and allow the record to be saved.

    I would also like to know how to do the above when the control to be highlighted is a check box.

    Thank you in advance


  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Are you using bound or unbound controls. This type of behavior is a lot harder (to me) with bound controls than unbound but I think it can be done either way.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Richmond (Virginia, not North Yorkshire!)
    More details are really needed for us to give you concrete advise.

    What type of Form are we talking about; Single, Continuous or Datasheet View?

    Are you saying if any selection is made from the Combobox, the Textbox needs to be populated, or if a specific selection is made the Textbox needs to be populated?

    Linq ;0)>
    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Here's a Validate function I wrote and use in a lot of different forms.

    Public Function Validate(ByRef ctrlBox As Control) As Boolean
    If ctrlBox.ControlType = 106 Then
    If ctrlBox Then 'validates that the checkbox has been checked
    Validate = True ctrlBox.BorderColor = RGB(31, 73, 125) Exit Function
    End If
    End If If ctrlBox.ControlType = 109 Or ctrlBox.ControlType = 111 Then
    If Not IsNull(ctrlBox.value) And ctrlBox.value <> "" Then
    Validate = True ctrlBox.BorderColor = RGB(31, 73, 125) Exit Function
    End If
    End If ctrlBox.BorderColor = RGB(255, 0, 0) If ctrlBox.Tag <> "" Then
    MsgBox ctrlBox.Tag, vbCritical, "Data Validation Failed"
    End If ctrlBox.SetFocus Validate = False
    End Function
    Just type your validation error message into the Tag field of each control and when you want to validate, pass it to this function. You can change up the decoration as you please - mine goes Red to Blue. It also sets focus on the failed control.

    So if you want it to check on a particular value in your Combobox you could do something like

    Select Case cboSomething
    Case "Your Mom"
       if Validate(txtYourmom) then 
       end if
    Case "DIAF"
       if Validate(chkInferno) then 
       end if
    Case Else
       if Validate(cboSomething) then
       End If
    End Select
    If validation fails, the Validate function will set the focus, border red, and provide an error message if one is in the Tag field.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 12-28-2012, 02:54 PM
  2. Replies: 1
    Last Post: 10-08-2012, 09:01 AM
  3. Replies: 2
    Last Post: 09-29-2012, 11:22 PM
  4. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  5. Replies: 16
    Last Post: 07-22-2011, 09:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums - Senior Forums