Solved

How do I wait for user input??

Posted on 2001-09-17
5
139 Views
Last Modified: 2010-05-02
In a function or sub, I want to pop up a form and have the code wait for the user to hit ok or whatever on the form before continuing.  How?

Example, a form is up with an empty listbox.  The user clicks on a button and a form pops up with a combobox.  The user selects what item he wants from the combobox and hits ok.  The form closes and the listbox is filled with the users selection.

I want it to be so that if I took out the other form popping up and user interaction, the listbox wouild fill up with default stuff.  I've seen where someone used an InputBox to get a typed in string, is there a similar way to do this where the user can use a combobox?

Thanks,
Jason
0
Comment
Question by:ramsejp
[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
5 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6488227
no there isn't one with a combo box on it.  you can write your own though.

on form put the combo box and an ok button
in declarations
public sub ChosenItem as string

in ok button click
chosenitem = cbo.text

in your sub or function

dim sTemp as string
mycomboform.show vbmodal
sTemp = mycomboform.ChosenItem
stemp now has the selected item from the user.  you can do checks on the form to make sure if they selected something add a label to the form and pass in the labels text to another var etc.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 6488380
Show this form modally:
form2.show vbModal
0
 
LVL 12

Expert Comment

by:roverm
ID: 6488414
Here's a sample project:

Code for form1 (containing a listbox and a commandbutton):

Option Explicit

Private Sub Command1_Click()
Dim frm As Form2

    Set frm = New Form2
    With frm
        .Show vbModal
        If .Combo1.ListIndex > -1 Then
            List1.AddItem .Combo1.Text
        End If
    End With
    Unload frm
   
    Set frm = Nothing
   
End Sub

code for form2 (containing a combobox and a commandbutton):

Option Explicit

Private Sub Command1_Click()
    Me.Hide
End Sub

Private Sub Form_Load()
    With Combo1
        .AddItem "1"
        .AddItem "2"
        .AddItem "3"
    End With
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If Not UnloadMode = vbFormCode Then Me.Hide
End Sub

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 6488416
BTW: I've set the BorderStyle of form 2 to 1-Fixed Single.
0
 

Author Comment

by:ramsejp
ID: 6488893
This is more what I had in mind.  Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

724 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