croy said:
Marshall Barton wrote:
croy wrote:
A form has a command button to launch a popup form for
records related to the first form.
I'd like to be able to indicate on the first form, whether
or not there are any records on the related (popup) form.
Something conversationally like, "if there is a related
record in the table associated with the popup form, make
this field's background color blue".
If I try to inch this along toward actual code, I get to,
frmIv_OnCurrent
If IsNotNull([tblFishCount]![IvId] where
[IvId]=Me![txtIvId])
If your form is displayed in single view, you could make
that sort of thing work:
Me.commandbutton.Enabled = _
DCount("IvId","tblFishCount","IvId=" & Me!txtIvId)=0
but you can not set the BackColor of cammand buttons so my
example used Enabled instead.
If table tblFishCount is related to the form's table by the
IvId field, then a better way would be to change the first
form's record source to be a query with an outer join of the
two tables and includes the on the IvId field from
tblFishCount:
SELECT T.*, R.IvId Is Not Null As DataExists
FROM yourtable As T LEFT JOIN tblFishCount As R
ON T.IvId = R.IvId
Then the code could be much simpler and faster:
Me.commandbutton.Enabled = Me.DataExists
This form is continuous (actually a subform), with command
buttons to open the popups on each line.
Using your excellent idea of the outer join, I put some code
in the OnCurrent event to change the color of the button
text (ForeColor). That works, but not quite like I had
hoped. When a main-form record comes up, for which any of
the associated subform records would change the button text
color, they all turn!
Any ideas on how to make this be more selective? (each row
on the subform show its conditional colors)
Ooohh, it's a continuous form. Well that changes just about
everything ;-)
You can not use VBA code to set control properties in a
continuous (or datasheet) form because there is only one
control that is displayed multiple times. So, it natuarally
follows that setting a property sets it for all rows.
The Conditional Formatting feature was added (in A2K) just
for this situation. Unfortunately, you can only use CF on
text boxes, so we'll have to play some tricks.
Use a text box instead of a button. To prevent users from
typing in the text box, set its Locked property to Yes. You
can make the text box look a lot like a button by setting
its SpecialEffect property to Raised.
With all that taken care of, use Conditional Formatting
(Format menu) to change the text box's appearance. Select
the Expression Is option and enter the expression:
[DataExists]
and then pick your favorite colors.