Solved

void 0 on a button

Posted on 2003-11-22
3
295 Views
Last Modified: 2010-05-01
Hi I'm just wondering if its possible to have buttons that executes code on click event without setting the button as focus.
Like in javascript we use "void 0;"

Example(I don't use a textbox in my project but dhtm editing component) :
We have an textbox and a button. Focus is on the textbox and then I press the button an click event adds "test" to the textbox. The textpointer is still blinking in the textbox.
0
Comment
Question by:thor918
[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
  • 2
3 Comments
 
LVL 9

Expert Comment

by:dancebert
ID: 9802866
No, but you can fake it.  In this code the button gets focus when you click it, but the click events shifts the focus to the text box.  The user nevers knows the button had focus but the program does, so the code in Command1_GotFocus executes.

Private Sub Command1_Click()
    Debug.Print "Button click"
    Text1.Text = "test"
    Text1.SetFocus
End Sub

Private Sub Command1_GotFocus()
    Debug.Print "Button got focus"
End Sub

Private Sub Form_GotFocus()
    Debug.Print "text1 got focus"
End Sub
0
 
LVL 9

Accepted Solution

by:
dancebert earned 50 total points
ID: 9802879
Oops, there was a typo.  The correct code is:

Private Sub Command1_Click()
    Debug.Print "Button click"
    Text1.Text = "test"
    Text1.SetFocus
End Sub

Private Sub Command1_GotFocus()
    Debug.Print "Button got focus"
End Sub

Private Sub Text1_GotFocus()        ''' this line changed
    Debug.Print "text1 got focus"
End Sub


0
 
LVL 2

Author Comment

by:thor918
ID: 9812484
The toolbar component will give me what I was looking for

Thanks for the help
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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