How are ya testkitt2 . . .
testkitt2 said:
[blue]I can't use conditonal formatting cause I dont know what will be typed into some of the textboxes . . . And to answer a previous question ...[purple]this is specific to only those records that require a highlight[/purple].[/blue]
[purple]
Since your hilighting is specific to any record, I don't see how you'll accomplish this without Conditional Formatting![/purple] . . . Have no fear for it can be done. Its a method I've used in enough of my DB's.
The method uses a [blue]packed string[/blue] (one character position per field you want to control). [blue]Each field on the form is handled by an assigned index into this string.[/blue] Each position of the string is either "0" or "1", with one of course enabling hilighting. The packed string resides in an [blue]added text field[/blue] in the underlying table.
The method uses the [blue]DoubleClick[/blue] event of the fields and is a [blue]toggle[/blue]. DoubleClick to hilight . . . DoubleClick to remove hilight. All you have to do is:
[ol][li]Add a new field to the underlying table.[/li]
[li]Update the default of the new field for all previously saved records.[/li]
[li]Copy the code.[/li]
[li]Call a common routine from the fields you wish to control.[/li]
[li]Set the conditional formatting for the fields of interest.[/li][/ol]
So lets get on with it . . .
[ol][li]In the underlying table of the form add a [blue]new field[/blue] with the following properties:
[ol a][li]Name [purple]
Flg[/purple][/li]
[li]Data Type [purple]
Text[/purple][/li]
[li]Field Size: [purple]
A number from 1 to 255 depicting the amount of fields you want to control. If you intend to add fields in the future use that total number instead. In any case its better to have a few more as no error checking is done for less.[/purple][/li]
[li]Default Value [purple]
as many zeros [blue]"0000 . . ."[/blue] as the Field Size (this is a textfield so include the double quotations).[/purple][/li][/ol][/li]
[li]Save & close the table[/li]
[li]We have to sidw step here as all previous records don't have the zeros "0000 . . ." for control and will error. So in a module in the modules window, copy/paste the following:
Code:
[blue]Public Sub DefFlg()
DoCmd.RunSQL "UPDATE [purple][b]YourTableName[/b][/purple] SET Flg = String([purple][b]FieldSize[/b][/purple],'0');"
End Sub[/blue]
[ol a][li]Don't forget to make the proper substitution for [purple]
YourTableName[/purple].[/li]
[li]Use the [purple]
Field Size[/purple] you used for the new field![/li]
[li]Open the Immediate window
and enter [blue]Call DefFlg[/blue] and hit enter.[/li][/ol][/li]
[li]With that done, open the form in [blue]design view[/blue] and be sure the new field is included the forms [blue]RecordSource[/blue]. Have a look at the Field List
for a quick check. It should appear there. If not . . . make it so. Remember the field doesn't have to be on the form, it just has to appear in the Field List.[/li]
[li]In the code module of the form, copy/paste the following:
Code:
[blue]Public Sub TglFlg(Idx As Integer)
Dim txt As String
txt = Me!Flg
If Mid(txt, Idx, 1) = "1" Then
Mid(txt, Idx, 1) = "0"
Else
Mid(txt, Idx, 1) = "1"
End If
Me!Flg = txt
Me.Refresh
End Sub
Public Function SetHiLite(Idx As Integer) As Boolean
Dim txt As String
txt = Me!Flg
If Mid(txt, Idx, 1) = "1" Then
SetHiLite = True
Else
SetHiLite = False
End If
End Function[/blue]
[ol a][li][blue]
TglFlg(Idx As Integer)[/blue] is the common routine called by the DoubleClick events of your controls of interest.[/li]
[li][blue]
SetHiLite(Idx As Integer)[/blue] is the function called by Conditional Formatting.[/li][/ol][/li]
[li]Now in the [blue]DoubleClick[/blue] event of the controls of interest, copy/paste the following, replacing [purple]
Index[/purple] with a number from 1 to the fieldsize you used. Each field should have a unique number:
Code:
[blue] Call TglFlg([purple][b]Index[/b][/purple])[/blue]
Write down the indexes you use for the controls to make it easier to setup conditional formatting which is next.[/li]
[li]Finally . . . [blue]Conditional Formatting.[/blue] For each field of interest conditional formatting should be:
Code:
[blue]Expression Is Mid([Flg],[purple][b]Index[/b][/purple],1)="1"[/blue]
[ol a][li]Set your colors and click OK.[/li][/ol][/li]
[li]Open your form and do your Testing![/li][/ol]
[blue]Let me know how ya make out! . . .[/blue]
See Ya! . . . . . .