Solved

Multiple command buttons sharing one event?

Posted on 1998-09-06
6
194 Views
Last Modified: 2006-11-17
Let's say that I have 5 command buttons on an Access 97 form.  All five buttons perform pretty much the same tasks, with one exception.  Rather than use 5 "OnClick" events, is it possible for all 5 command buttons to use one and the same event?  If 'yes', then how?  Then, how can I perform a Select Case within this single event to determine which button of the 5 that actually triggered the event?  This way I can minimize the amount of duplicate coding, while at the same time make sure that the unique code related to each command button is run.
0
Comment
Question by:Monroe406
[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
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Helicopter
ID: 1961340
create a function (say myfunction()) which takes a string as a parameter

call the function from the onclick events of your 5 buttons and pass the name of the command button with it.

If the uniqueness can be further refined you only need to pass the element that is unique to the function, the actual command button name isn't necessary
0
 

Author Comment

by:Monroe406
ID: 1961341
Thanks.

I wanted to ask some new questions, however, it looks like Experts Exchange's "Ask a ?" function is temporarily broken:

File Not Found

The requested URL /topics/bin/NewQForm was not found on this server.

In any case, here are some new questions:

1) How does one define a GLOBAL constant value that is accessible from ALL modules/forms?

2) How can I check whether a file for input exists PRIOR to opening it?  Likewise, how can I verify whether a directory exists or not?  In Delphi/Pascal, it would be "If FileExists("c:\autoexec.bat") then...".  In PowerBasic, it would be "Dir$("c:\autoexec.bat")".

0
 
LVL 5

Accepted Solution

by:
kulikuli earned 50 total points
ID: 1961342
Public constant for all modules/forms:
In a standard module: Public const MYCONSTANT as string="mystringvalue"
File exits check:
use the Dir() function. if it generates an error the directory does not exist. If no error occures you are able to determine if the file you want to create already exist.

Best regards,

kulikuli
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Monroe406
ID: 1961343
Since it is still impossible to ask a new question via "Ask a ?"

--------------
File Not Found

       The requested URL /topics/bin/NewQForm was not found on this server.
--------------

.I am going to press my luck and ask another question here:

Is there a way to retrieve the value of a Text component withOUT having to SetFocus first?  Currently, this is illegal:

MyString = Text1.Text

.unless I do this first:

Text1.SetFocus
MyString = Text1.Text

Is there a more efficient solution?  Setting focus prior to referencing the Text component's data won't always work, as in...

MyString = Text1.Text + " " + Text2.Text

Thanks.
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1961344
Try putting me before hand

MyString = me.Text1 & " " & me.Text2

you shouldn't need to set focus.
0
 

Author Comment

by:Monroe406
ID: 1961345
Thanks Helicopter!  That worked great!

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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.
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…

756 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