Solved

How do I wait for user input??

Posted on 2001-09-17
5
134 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
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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

939 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

10 Experts available now in Live!

Get 1:1 Help Now