By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,844 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,844 IT Pros & Developers. It's quick & easy.

How to create Command Button that know which form to open

P: 1
In ACCESS 2007 I have 2 tables that are in a 1-to-many relationship, and the Primary Key for Table A is in both Tables. I have a form with data from Table A and a command button that opens up another form to allow users to add data to Table B. This form is a split form and works very well when there are existing records in Table B. The split form (Table B data) has a sub-form with Table A data and the command button links the Table A primary key (Table A = Sub form) . It does works really well Ė when Table B already has a record created from Table A.
The split form will not work when there isnít a record created in Table B yet. To get around that Iíve created another form that will create a new record and it works like itís supposed to as well.
This is where I need assistance: The first form from Table A has two Command Buttons under a question:

Cmd 1= Yes, take me to the Records list
Cmd 2= No, I need to create a Record

My issue is I have to trust the user to hit the right button. Is there a way I can create a macro or code behind just one Command Button to go to either form based on whether or not the Table A Primary Key exists in Table B?
Iím not as experienced in ACCESS as I would like to be and do not know very much about coding. Iíll take any recommended reading thatís offered as wellÖ. Thanks for any help you can provide.
Apr 12 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 31,307
Unless I misunderstand your question, you simply want to determine if a particular record exists in a table. The DLookup() command will do that for you. Null is returned when no matching record exists.
Apr 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.