Solved

How do I wait for user input??

Posted on 2001-09-17
5
137 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
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…

756 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