Solved

Check command button status on another form

Posted on 2013-12-23
5
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 39736758
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
ID: 39736875
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
ID: 39736905
Exactly!  Thanks Fyed
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39736922
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)
ID: 39736925
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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