Solved

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

Posted on 2011-09-08
4
311 Views
Last Modified: 2013-11-05
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
0
Comment
Question by:SteveL13
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36505437
use the current event of the form

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

Author Comment

by:SteveL13
ID: 36505486
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
 
LVL 9

Expert Comment

by:borki
ID: 36505568
You can add a where condition to the form, such as:

DoCmd.OpenForm("frmsecondOne",,,"JobN=" & me.txtJobN)
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 36505735
private sub command0_click()

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

end sub
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now