How to create Command Button that know which form to open

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kelhisu77
    New Member
    • Apr 2013
    • 1

    How to create Command Button that know which form to open

    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:

    HAS A RECORD BEEN CREATED FOR THIS POST YET?
    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.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    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.

    Comment

    Working...