A better way...

KenHigg

Registered User
Local time
Today, 16:55
Joined
Jun 9, 2004
Messages
13,291
I trying to find a more effeicent way of coding the following examples and was hoping someone here could offer some suggestions:

Code:
With Me
        recno.BorderColor = lngDefaultColor
        customer_id.BorderColor = lngDefaultColor
        requested_date.BorderColor = lngDefaultColor
        shpd_date.BorderColor = lngDefaultColor
End With

And:

Code:
Select Case t_sortString
        Case "recno"
            Me!recno.BorderColor = lngHighlightColor
        Case "customer_id"
            Me!customer_id.BorderColor = lngHighlightColor
        Case "requested_date"
            Me!requested_date.BorderColor = lngHighlightColor
        Case "shpd_date"
            Me!shpd_date.BorderColor = lngHighlightColor
End Select

They basically just turn some screen stuff off and on.

thx, kh
 
I just thought I may be able to loop through the control refs programmatically.

There are actually twice that number of controls, but I had to cut them out for privacy reasons...

kh
 
G’day Ken.

Code:
    [color=green]'   This one...[/color]
    
    Select Case t_sortString
        Case "recno"
            Me!recno.BorderColor = lngHighlightColor
        Case "customer_id"
            Me!customer_id.BorderColor = lngHighlightColor
        Case "requested_date"
            Me!requested_date.BorderColor = lngHighlightColor
        Case "shpd_date"
            Me!shpd_date.BorderColor = lngHighlightColor
    End Select

    
    [color=green]'   Seems to condense to...[/color]
    
    Me(t_sortString).BorderColor = lngHighlightColor
Hope that helps.

Regards,
Chris.
 
Code:
Me(t_sortString).BorderColor = lngHighlightColor

Something told me I was missing something - cool!

Thanks for your suggestion Giz, I'll give it a look in the am.

kh
 
G’day Ken and Uncle_Gizmo

I know you now see just what is going on here but others may not.
If we format it slightly differently it might become more obvious.

There is a hard coded cross-reference within the Select Case structure.

Code:
    Select Case [color=green]t_sortString[/color]
        Case "[color=red]recno[/color]"
           Me![color=red]recno[/color].BorderColor = lngHighlightColor
        Case "[color=blue]customer_id[/color]"
           Me![color=blue]customer_id[/color].BorderColor = lngHighlightColor
        Case "[color=Cyan]requested_date[/color]"
           Me![color=Cyan]requested_date[/color].BorderColor = lngHighlightColor
        Case "[color=Magenta]shpd_date[/color]"
           Me![color=Magenta]shpd_date[/color].BorderColor = lngHighlightColor
    End Select
    
    
    Me([color=green]t_sortString[/color]).BorderColor = lngHighlightColor
Hard coding a cross-reference would require changing the source code.
That is why it should be condensed.

Hope that helps all.

Regards,
Chris.
 
Last edited:
I've already written this post once and it got lost...

How about something like:

Code:
For Each ctl in Me.Controls
  If ctl.ControlType = acSubForm Then
     ctl.BorderColor = lngHighlightColor
  End If

Change the control type to whatever it is

If you want to exclude some, give them a name such as "ctlMyTextBoxExc" and then make the If line

Code:
If ctl.ControlType = acTextBox And Not (Right(ctl.Name,3) = "Exc") Then

Nick
 
You could just dump the code in a Class module so that you don't have to bother with it anymore and, from your forms, it will only be a minimal line or to to use the class.
 
SJ McAbney said:
You could just dump the code in a Class module so that you don't have to bother with it anymore and, from your forms, it will only be a minimal line or to to use the class.

Might I impose on you to elaborate just a bit?

kh
 

Users who are viewing this thread

Back
Top Bottom