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
SteveL13Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
private sub command0_click()

docmd.openform "form2",,,"JobN=" & me.txtJobN

end sub
0
 
Rey Obrero (Capricorn1)Commented:
use the current event of the form

me.command0.visible=dcount("*","NameOF2ndTable", "JobN=" & me.txtJobN)>0
0
 
SteveL13Author Commented:
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?

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

DoCmd.OpenForm("frmsecondOne",,,"JobN=" & me.txtJobN)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.