Are you certain that the names match between the DCount and the table/form?
The way I read it, in the table that the subform is based on the field name
should be RecordID and on your main form the control name should be
Record_ID. Is this correct? Put a breakpoint on the line that contains the
DCount call, then run the form. When the code window opens, open the
Immediate window (Ctrl-G) and enter:
? DCount(...
reproducing the DCount code exactly. What do you get as a result? If you
"hover" the mouse over the Me.Record_ID in the DCount call in the code
window (not the Immediate window), you should see the actual value that is
being used. Are you certain there are records for that value?
As a note, forms and subforms don't have primary keys; tables do. The forms
must be based on a table or query. In the table or query that the form is
based on, is the field name RecordID or Record_ID? In the main form and the
subforms, what is the name of the control that is bound to the record id
field of the underlying table?
Lastly, when you say "can't get to", what does that mean? Is the tab control
disabled or locked? What happens when you click on each tab?
Carl Rapson
> Thanks Carl, I inserted this in just as you have it (and yes, it is
> RecordID
[quoted text clipped - 79 lines]
>>
>> Carl Rapson
Carrie - 15 May 2007 22:13 GMT
My mistake Carl - something actually must have happened to my database. I
deleted the whole thing, re-did it and it is working great with your code but
I still seem to be missing something.
Below is how each Case looks. What is happening now is that the button does
only show red if there is data on the subform, AFTER I click on the toggle
button. And, if I go to a different record, the subform that had data
previously, will still have a red font toggle button until I click it again
(then it turns black).
Is there a way to make this work so that when I go to a new record, either
by scrolling, or searching that the correct toggle buttons will appear red or
black for the appropriate Record_ID (Frm_MAIN which has a record source of
Tbl_MAIN) without having to click first?
Thanks a lot!
Case 1
Me!TABS.Value = 0
x = Nz(DCount("Aband_ID", "Qry_Abandonments", "RecordID=" & Me.Record_ID),
0)
If x > 0 Then
Me.Tog_Abd.ForeColor = vbRed
Else
Me.Tog_Abd.ForeColor = vbBlack
End If
> Are you certain that the names match between the DCount and the table/form?
> The way I read it, in the table that the subform is based on the field name
[quoted text clipped - 104 lines]
> >>
> >> Carl Rapson
Carl Rapson - 16 May 2007 16:12 GMT
> My mistake Carl - something actually must have happened to my database. I
> deleted the whole thing, re-did it and it is working great with your code
[quoted text clipped - 27 lines]
> Me.Tog_Abd.ForeColor = vbBlack
> End If
<snipped remainder>
Try putting code in the Form_Current event to set the button color.
Carl Rapson