Solved

Check command button status on another form

Posted on 2013-12-23
5
375 Views
Last Modified: 2013-12-23
I have a switchboard that opens a form.  The switchboard has three command buttons: cmdBrowse, cmdEdit, cmdNew.   They all open the same form.  I want to set up the form according to which button was selected.  How can I know what button was selected?

I've been trying code like:
If Forms![Switchboard]![cmdBrowse] = True

Thanks,
Brooks
0
Comment
Question by:gbnorton
  • 3
5 Comments
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
You may open the form with parameter to add or edit or readonly
DoCmd.OpenForm "a", acNormal, , , acFormAdd
DoCmd.OpenForm "a", acNormal, , , acFormEdit
DoCmd.OpenForm "a", acNormal, , , aacFormReadOnly
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
Another way to do it is from one of the Form2 events, probably the Open, Load, or Timer event, with code like:

Select Case Form_Form1.activecontrol.name
    Case "cmdBrowse"
        'do something here
    Case "cmdEdit"
        'do something here
    Case "cmdNew"
        'do something here
End Select
 
You could also use:

Select Case Forms("Form1").activecontrol.name
0
 

Author Closing Comment

by:gbnorton
Comment Utility
Exactly!  Thanks Fyed
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Glad to help.  

This should normally work, but if the code behind the click event of one of those buttons on your first form sets the focus to another control then you may not get the results you are expecting.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Another way would be to use the OpenArgs argument of the OpenForm method and pass the name of the commandbutton, something like:

docmd.OpenForm "formname",,,,,acDialog, "cmdBrowse"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 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

11 Experts available now in Live!

Get 1:1 Help Now