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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeating field in subform

Status
Not open for further replies.

toddsavage100

Programmer
Mar 12, 2008
1
GB
Ok small problem,

I have a subform with the field ChildID, and i need some code so that it is not possible to select the same value for ChildID more than once in the form. I have attached a image of what i am talking about, the highlighted fields show what i want the end user to not be able to do! Maybe some Onlostfocus code which displays a msgbox when repeating data is entered? Please help its for my coursework and we haven't even been taught VBA, they just expect us to do it! Thanks
 
Two ideas for you

1. Put a unique index on ChildId, in the underlying table, or I suspect more appropriate put a unique index in the compound GroupiD;ChildId where GroupId identifies the "collection" you are defining in your subform

2. Use code to loop through the recordset of the subform and check for duplicates

Personally I prefer the first option

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Unique indexes are often useful. Alternatively, you could FindFirst using the Recordset or RecordsetClone in, say, the Before Update event because that can be cancelled.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top