B
Bill Mitchell
Hi,
I've been messin around with this for days and I think I
have come up with a very cool and very easy method for
making an Unbound Control on a continuous form display
pretty much any value when the current record has the
focus on that record only and no others.
This works great if you are trying to make the current
line a different color or check a box for the current
line.
Actually, I'm not really sure why all of this works, but
it does and takes almost no code at all
Example:
Lets say we have a continuous form based upon a table
called "Contact". Let's say the Primary Key on that
table is called "ContactID". ContactID exists as a field
on our continuous form.
We need to place two UNBOUND fields on our form:
1. A field called "ctlCurrentRecord"
2. A Checkbox call "ContactSelector"
Our goal will be to make ContactSelector 'checked' when
we select the active record but 'unchecked' for all
unselected records.
Ok, now in your OnCurrent Event for your continuous form,
place this code:
'Set Record Selector:
Me.ctlCurrentRecord = Me.SelTop
If IsNull(Me![ContactID]) Then
Else
Me.ContactID.Tag = Me.ContactID
End If
Finally, set the value of your "ContactSelector" unbound
checkbox to:
=IIf([Form].[KeywordID].[Tag]=[Form].[KeywordID],-1,0)
Ok, now when you select a record, the checkbox for that
record will be checked and all others unchecked. When
you leave that record and go to another record, it works
too.
Pretty cool huh?
Lastly, if you want to change a row color using this, try
this way:
Make "ContactSelector" a textbox rather than a checkbox.
Set the font to "Terminal" and the forecolor for the font
to whatever color you want your row to be. Now set the
value of "ContactSelector" to:
=IIf([Form].[ContactID].[Tag]=[Form].
[ContactID],"ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Û",Null)
You will need to make your form background WHITE and the
your field backcolors set to the same color as
your "ContactSelector" forecolor and set to Transparent.
Place "ContactSelector" behind the fields you want to
change color when the row is selected.
Anyway, it works like a charm and almost no code.
Last Comment:
You may be wondering why I need the "ctlCurrentRecord" to
be set to me.SelTop for each record selected. Honestly,
I'm not sure, but I know it doesnt work without it
Bill
Any MVP comments appreciated.
I've been messin around with this for days and I think I
have come up with a very cool and very easy method for
making an Unbound Control on a continuous form display
pretty much any value when the current record has the
focus on that record only and no others.
This works great if you are trying to make the current
line a different color or check a box for the current
line.
Actually, I'm not really sure why all of this works, but
it does and takes almost no code at all
Example:
Lets say we have a continuous form based upon a table
called "Contact". Let's say the Primary Key on that
table is called "ContactID". ContactID exists as a field
on our continuous form.
We need to place two UNBOUND fields on our form:
1. A field called "ctlCurrentRecord"
2. A Checkbox call "ContactSelector"
Our goal will be to make ContactSelector 'checked' when
we select the active record but 'unchecked' for all
unselected records.
Ok, now in your OnCurrent Event for your continuous form,
place this code:
'Set Record Selector:
Me.ctlCurrentRecord = Me.SelTop
If IsNull(Me![ContactID]) Then
Else
Me.ContactID.Tag = Me.ContactID
End If
Finally, set the value of your "ContactSelector" unbound
checkbox to:
=IIf([Form].[KeywordID].[Tag]=[Form].[KeywordID],-1,0)
Ok, now when you select a record, the checkbox for that
record will be checked and all others unchecked. When
you leave that record and go to another record, it works
too.
Pretty cool huh?
Lastly, if you want to change a row color using this, try
this way:
Make "ContactSelector" a textbox rather than a checkbox.
Set the font to "Terminal" and the forecolor for the font
to whatever color you want your row to be. Now set the
value of "ContactSelector" to:
=IIf([Form].[ContactID].[Tag]=[Form].
[ContactID],"ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Û",Null)
You will need to make your form background WHITE and the
your field backcolors set to the same color as
your "ContactSelector" forecolor and set to Transparent.
Place "ContactSelector" behind the fields you want to
change color when the row is selected.
Anyway, it works like a charm and almost no code.
Last Comment:
You may be wondering why I need the "ctlCurrentRecord" to
be set to me.SelTop for each record selected. Honestly,
I'm not sure, but I know it doesnt work without it
Bill
Any MVP comments appreciated.