Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Make command button visible if record exists in a 2nd table

I have a command button on a form which has a query as its record source.  The query comes from a table that has a number field as its key field.  The name of the field in the table is "JobN" and there is a field on the form named "txtJobN" which has the key table field as its control source.

The command button by default is not visible.  But I want it to become visible if there is a like entry in a second table.  This second table has a key field identical to the key field in the 1st table.  What would the code be for the onopen (or would it be oncurrent?) event of the form?

Then, when the command button becomes visible and is clicked, I want a form to open to display the record in the second table.

What is my onclick event for the command button?

--Steve
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

use the current event of the form

me.command0.visible=dcount("*","NameOF2ndTable", "JobN=" & me.txtJobN)>0
Avatar of SteveL13

ASKER

Good so far...

And then,

When the command button becomes visible and is clicked, I want a form to open to display the record in the second table.

What is my onclick event for the command button?

You can add a where condition to the form, such as:

DoCmd.OpenForm("frmsecondOne",,,"JobN=" & me.txtJobN)
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial