Solved

void 0 on a button

Posted on 2003-11-22
3
288 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now