Solved

How do I wait for user input??

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 77
I need help embedding an image as HTML in my vb.net application 3 73
Child Form in front 4 49
fso.FolderExists("\\server\HiddenFolder$") 4 78
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…

840 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