What Control To Use

D

dhstein

I want to show a button that the user will click and get a textbox to enter
one item. Then when he hits return, the action will take place. Is that a
Combo Control or is there some better one. Also, which event would I use
(xxxControlName_Click-Or_What) ? Also, I'm confused about when I have to
deal with the focus on events. Any help with any or all of these questions
is appreciated. Thanks.
 
D

Dirk Goldgar

dhstein said:
I want to show a button that the user will click and get a textbox to enter
one item. Then when he hits return, the action will take place. Is that
a
Combo Control or is there some better one. Also, which event would I use
(xxxControlName_Click-Or_What) ? Also, I'm confused about when I have
to
deal with the focus on events. Any help with any or all of these
questions
is appreciated. Thanks.


It sounds to me like you need two controls, a command button and a text box,
or else a command button that calls the InputBox function to request the
user's input. If I understand what you want, you could do it either way.

If you use two controls, you could have the text box be invisible until the
code in the command button's Click event shows it and sets the focus to it.
Then you could use the AfterUpdate event of the text box to execute your
action, and the Exit event of the text box to hide the text box again. (You
show and hide a control by setting its Visible property to True or False, as
desired.)

Alternatively, you could just have the command button with no text box, but
call the InputBox function in the button's Click event procedure to get the
user's input, then act on it. That would look like this:

'----- start of example code ----
Private Sub cmdYourButton_Click()

Dim strInput As String

strInput = InputBox("Enter something, please:")

If Len(strInput) = 0 Then
' The user entered nothing; act appropriately.
Else
' The user's entry is in strInput. Do something with it.
End If

End Sub
'----- end of example code ----
 
D

dhstein

Dirk Goldgar said:
It sounds to me like you need two controls, a command button and a text box,
or else a command button that calls the InputBox function to request the
user's input. If I understand what you want, you could do it either way.

If you use two controls, you could have the text box be invisible until the
code in the command button's Click event shows it and sets the focus to it.
Then you could use the AfterUpdate event of the text box to execute your
action, and the Exit event of the text box to hide the text box again. (You
show and hide a control by setting its Visible property to True or False, as
desired.)

Alternatively, you could just have the command button with no text box, but
call the InputBox function in the button's Click event procedure to get the
user's input, then act on it. That would look like this:

'----- start of example code ----
Private Sub cmdYourButton_Click()

Dim strInput As String

strInput = InputBox("Enter something, please:")

If Len(strInput) = 0 Then
' The user entered nothing; act appropriately.
Else
' The user's entry is in strInput. Do something with it.
End If

End Sub
'----- end of example code ----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Dirk,

I'm going to work with your example - since I'm just learning it might
take me a little while, but I wanted to thank you for your very thorough and
informative response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top