View Full Version : Enable/disable button based on lookup on another table


daninthemix
01-12-2006, 09:11 AM
I have an 'associated' button on one form that jumps to another form and shows the associated record via the common field. However, that data may not necessarily be there - in other words, it'll be in the first form but the matching data may not be present in the other form, meaning it opens blank.

What's the best way to have Access lookup that data to see if it's there, and if it isn't to disable the button?

KenHigg
01-12-2006, 09:18 AM
Maybe you could use a dlookup() here to see if anything is there before you actually open the form...

daninthemix
01-12-2006, 09:55 AM
Maybe you could use a dlookup() here to see if anything is there before you actually open the form...

Thanks Ken. Can you help with the syntax? I've got


Dim CarePackExists As Variant
CarePackExists = DLookup("[Care Pack ID]", "Care Packs", "[Care Pack ID] = " _
& Forms!Serials![Care Pack ID])
cmdViewCarePack.Enabled = Not IsNull(CarePackExists)


Am I right in thinking this will pull the first value from FIELD Care Pack ID in table Care Packs where it matches the value in FORM serials, field Care Pack ID?