Solved

Multiple command buttons sharing one event?

Posted on 1998-09-06
6
190 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
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Helicopter
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Monroe406
Comment Utility
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
Comment Utility
Try putting me before hand

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

you shouldn't need to set focus.
0
 

Author Comment

by:Monroe406
Comment Utility
Thanks Helicopter!  That worked great!

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 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

16 Experts available now in Live!

Get 1:1 Help Now