i created an unbound form. in that form i want to search/find a record in a table to check if the record exist. how do i code it. thanks.
i created an unbound form. in that form i want to search/find a record in a table to check if the record exist. how do i code it. thanks.
Take a look at the DCount() function and the criteria that can be used. If it returns 0 then no record exists.
If this helped, please click the star at the bottom left of this posting and add to my reputation. Many thanks.
Bob Fitzpatrick
many thanks that works.
i am using the same dcount() function in other forms to check for existing records in a table. on that form i code it on the on delete event to check for the record on another table. how do i code it to stop/prevent if the dcount() is > 0. i know the if statement however i am not familiar with ms access function to stop/prevent a delete. thanks.
for example.
Code:Dim vCount vCount = DCount("room_id", "tblClassLine", "room_id = " & [Forms]![frmRoom]![room_id]) if vCount > 0 then stop end if
Cancel=True
This applies to all events that have it as a parameter/provide it as an option.
You could also set the referential integrity in the Relationships window to prevent deletions.