Solved

How do I wait for user input??

Posted on 2001-09-17
5
133 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
5 Comments
 
LVL 3

Expert Comment

by:jrspano
Comment Utility
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 69

Accepted Solution

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

Expert Comment

by:roverm
Comment Utility
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
Comment Utility
BTW: I've set the BorderStyle of form 2 to 1-Fixed Single.
0
 

Author Comment

by:ramsejp
Comment Utility
This is more what I had in mind.  Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now