Highlight

connerlowen

Registered User.
Local time
Today, 17:50
Joined
May 18, 2015
Messages
204
Hi,

I am creating a database to generate quotations based on information that employees will input. I was wondering if there was a way to highlight the box they are on within a form, and if the value is the wrong type maybe highlight it red? If this is at all possible please tell me. I want to thank all of the users on here, you have all made my job a lot less stressful.

Thanks.
 
Sure it is but you're going to have to plan out points of validation parsing and also what your valid values are.
 
Dan's comments are appropriate. First decide if you want to do highlighting now.

Then, if you do, you can make a text box have three different colors. The BorderColor is the perimeter of the box, a rim that can be bright or dark and any color. The BackColor is the background of the box. The ForeColor is the color of the print in the box. You can highlight the box by changing those colors. There is an RBG function that you can use to define the saturation of the component colors. Look up these properties and functions.

As to when you do this, it could be in the control's LostFocus routine or it could be in some other event code.
 
Highlighting is doable - see the site of the master (check out all the other posts there, it's a veritable gold mine): http://allenbrowne.com/highlight.html

But a word of warning. Most apps consist of two types of features: "must have" and "nice to have". Think carefully about how much effort you want to invest in the nice-to-haves, that by nature of their definition do not add essential functionality to your application.
 
This is something I quickly whipped up for you to start with. I'm very sure that it will need more testing and some proper validation parsing, but it is a start.

Place this in a new module named _Util or something.
Code:
Public Sub ValidateControl(ByRef ctrl As Control, ByVal data_type As DataTypeEnum)
    
    Dim val As Variant: val = ctrl.Value
    Dim valid As Boolean
    
    Select Case data_type
    
        Case DataTypeEnum.dbDate:
        
            ctrl.BorderColor = IIf(IsDate(Nz(val, vbNullString)), vbGreen, vbRed)
            
        Case DataTypeEnum.dbDecimal:
        
            ctrl.BorderColor = IIf(IsNumeric(val), vbGreen, vbRed)
                
        Case DataTypeEnum.dbDouble:
        
            valid = IsNumeric(val) And _
                    val >= -7.92281625142643E+28 And _
                    val <= 7.92281625142643E+28
                    
            ctrl.BorderColor = IIf(valid, vbGreen, vbRed)
        
        Case DataTypeEnum.dbInteger:
        
            valid = IsNumeric(val) And _
                    val >= -32768 And _
                    val <= 32767
                
            ctrl.BorderColor = IIf(valid, vbGreen, vbRed)
            
        Case DataTypeEnum.dbLong:
        
            valid = IsNumeric(val) And _
                    val >= -2147483648# And _
                    val <= 2147483648#
                
            ctrl.BorderColor = IIf(valid, vbGreen, vbRed)
            
        Case DataTypeEnum.dbText:
            
            valid = Len(val & vbNullString) > 0
                
            ctrl.BorderColor = IIf(valid, vbGreen, vbRed)
            
    End Select
    
End Sub

Then use this in the onleave events of your controls.
Code:
Private Sub txtOne_LostFocus()
    ValidateControl txtOne, dbDouble
End Sub
 
I suspect you may be trying to do something in an over-complicated way

You might also consider the use of an Input Mask (You'll see it as a property on the fields in the table designer, click F1 there)
 
Just sticking with the initial request. I also enjoy creating such dynamic functions that display themselves visually to the user.

Complicated for the developer, quick, less irritating than a dialog box and nice on the eyes for the user. :P
 

Users who are viewing this thread

Back
Top Bottom