?
Solved

How to get the information froma a form

Posted on 2003-03-30
6
Medium Priority
?
140 Views
Last Modified: 2010-04-07
Hi all,

I create a form to ask the user to enter their name, How coud I can get that information then close the form. Here is my code, but something wrong

sub main1 ()

Set UserForm = New Inputform
'show the form
UserForm.Show

'display the information captured from the form.
MsgBox username

end sub

/the following code is the code for the OK button of the form
Private Sub OKButton_Click()
'here try to set the value of username (string to the value of the textbox (User) in the form)
username = User.value
End Sub

Thanks,

haoyu
0
Comment
Question by:haoyux
[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
6 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 8235250
Are you working with VBA or VB ?
0
 

Expert Comment

by:pkmnfrk
ID: 8235257
You need to make username a public variable:

Public username as String
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8235258
You ment something like this ?

Private Sub Form_Load()
Dim Username As String
Username = InputBox("Enter your name please...", "Name Input")
MsgBox "You have entered : " & Username, vbOKOnly
Unload Me
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:bistrica
ID: 8235269
create global variable as:

public gUserName as string
sub main1 ()

Set UserForm = New Inputform
'show the form
UserForm.Show

'display the information captured from the form.
MsgBox gUserName

end sub

/the following code is the code for the OK button of the form
Private Sub OKButton_Click()
'here try to set the value of username (string to the value of the textbox (User) in the form)
gUserName = User.text
End Sub
0
 

Author Comment

by:haoyux
ID: 8235279
main1 is the VBA code in excel

Then I create a form to ask the user to enter user name and group number.

I want to the following behavior

1. click a button in the excel

2. run the main1 sub

3. the form appears

4. user enters name and group number

5. user clicks the OK button in the form

6. form disappears

7. return the the main1 sub, I use msgbox to show the user's entering.

Thanks,

haoyu
0
 

Accepted Solution

by:
pkmnfrk earned 200 total points
ID: 8241308
Ok, here we go:

This goes under the button:

Private Sub cmdName_Click()
    frmUsername.Show 1           'Show dialog box
    uname = frmUsername.txtName  'Get name
    gnum = frmUsername.txtNumber 'Get number
    Unload frmUsername           'unload dialog box
    MsgBox uname                 'Display info
End Sub

This goes in the Ok button on the dialog:

Private Sub cmdOk_Click()
    Me.Hide
End Sub

That's all there is to it. For the code above, the dialog should have two textboxes named txtName and txtNumber, and one command button named cmdOk. The Excel sheet should have a button named cmdName.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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