Solved

Check command button status on another form

Posted on 2013-12-23
5
386 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
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 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

22 Experts available now in Live!

Get 1:1 Help Now