Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking whether a condition is true on a subform

Status
Not open for further replies.

mattl72

IS-IT--Management
Oct 2, 2002
24
US
Hi all,

First post :)

I am working on developing an inventory database that tracks item and bin info.

I have a main form with the item no, description, etc. There is a datasheet subform on the main form that tracks bin no, bin loc, and a yes/no checkbox that tracks whether the bin is primary or not. I need to check is whether a particular item has at least one - but no more than one - primary bin checked (an item can have multiple bins). Is there anyway to do this in the form? Perhaps in the code?

Hope this makes sense. Thanks in advance for your help.
 
Matt,

I am assuming the the parent and child form are from two related tables.

You can test this from the parent form using a dcount function setting the criteria that the same criteria that links the parent form and the child form.

Use in this format:
dim count as variant
Count = DCount("childID", "ChildTableName", "ParentID = " & me.ParentID & " and PrimaryBin = 1")

This will return the number of records (childIDs) that have the primaryID selected for a particular ParentID. In this case the parentID of the Parent Form.

Note that DCount returns a variant. If the statement does not find any records that match the criteria, it returns a null value.

Good Luck
Pat B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top