Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2015, 10:43 AM
benn benn is offline Help with VBA userform Windows 7 64bit Help with VBA userform Office 2007
Novice
Help with VBA userform
 
Join Date: Mar 2015
Posts: 1
benn is on a distinguished road
Default Help with VBA userform

Hello, so I am a student and I was asked to create a quiz for my IT project.
I wanted to add macros and so here is my problem.
When I click start, I want a user form to pop up and ask for the users name, and store the input in the variable UserId.
I have created the userform, and it works fine, but the variable doesn't seem to pick up what is written in the text box.
Here is my code for this specific section:
------------------------------------------------------------------------
Private Sub TextBox1_Change()
UserId = TextBox1.Text
End Sub

Private Sub ToggleButton1_Click()
MsgBox ("Thank you," & UserId)
End Sub
-------------------------------------------------------------------------


Currently, the Thank you, & user ID currently reads
Thank you,[BLANK]
Thanks in advance for any help
Kind regards, Benn
Reply With Quote
  #2  
Old 03-02-2015, 11:32 AM
JohnWilson JohnWilson is offline Help with VBA userform Windows 7 64bit Help with VBA userform Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,859
JohnWilson will become famous soon enoughJohnWilson will become famous soon enough
Default

Although you haven't declared the variable (and you should) PowerPoint will assume it to be declared in the Private sub. Because it is private to this sub only it cannot be used elsewhere.

Declare it like this
'Outside iof the private sub
Dim UserID As String

Private Sub TextBox1_Change()
UserID = TextBox1.Text
End Sub

Private Sub ToggleButton1_Click()
MsgBox ("Thank you," & UserID)
End Sub
__________________
Microsoft PowerPoint MVP
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
Reply

Tags
help please, userform, vba code

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with VBA userform Keep Userform on Top didjee PowerPoint 5 10-20-2014 02:22 PM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
Help with VBA userform Is it possible to take an input from a UserForm in one document to a UserForm in a do BoringDavid Word VBA 5 05-09-2014 09:08 AM
Help with VBA userform Checkbox in Userform lukael Excel Programming 5 02-18-2014 05:20 AM
Userform Code not quite right - help please vbanovice Word VBA 1 09-29-2013 09:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft