Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2017, 07:01 AM
Larry_1 Larry_1 is offline Assigning a string variable to a userform label caption Windows 10 Assigning a string variable to a userform label caption Office 2010 64bit
Novice
Assigning a string variable to a userform label caption
 
Join Date: Dec 2017
Posts: 9
Larry_1 is on a distinguished road
Default Assigning a string variable to a userform label caption

I a beginner with Excel.

I've created UserForm1 with 3 labels and 3 textboxes (email, first name, last name), captured the entries and validated them. I then wanted to use those values as captions in UserForm 2. But I couldn't make UserForm2 work. So I created a simple test form to try it, and couldn't make that work either. I've tried both a hard coded string and a simple string variable. Neither worked. I placed this code in the VBA area attached to the UserForm.

I would sincerely appreciate any suggestions that you can offer.



Very respectfully,
Larry


Code:
Private Sub UserForm_Click()

    Dim strTestValue As String
    
    strTestValue = "This is the test value"
    Label1.Caption = strTestValue
    'Label1.Caption = "This is the soft entered Msg"
    'Me.Label1.Caption = strTestValue
    
    End Sub
Reply With Quote
  #2  
Old 12-17-2017, 07:43 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Assigning a string variable to a userform label caption Windows 7 64bit Assigning a string variable to a userform label caption Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,779
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Hi and welcome
in the future please wrap code with code tags ( click -Go advanced - select code - click the #button)
I did it for you this time
Thx
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #3  
Old 12-17-2017, 09:37 AM
NoSparks NoSparks is offline Assigning a string variable to a userform label caption Windows 7 64bit Assigning a string variable to a userform label caption Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Try
Code:
Private Sub UserForm_Click()

    Dim strTestValue As String
    
    strTestValue = "This is the test value"
    
    With UserForm2
        .Label1.Caption = strTestValue
        .Show
    End With

End Sub
Reply With Quote
  #4  
Old 12-18-2017, 06:59 AM
Larry_1 Larry_1 is offline Assigning a string variable to a userform label caption Windows 10 Assigning a string variable to a userform label caption Office 2010 64bit
Novice
Assigning a string variable to a userform label caption
 
Join Date: Dec 2017
Posts: 9
Larry_1 is on a distinguished road
Default Thank you!

I know that, in the fields where I have significant experience, one difficulty in talking to beginners is that what's blindingly obvious to a person with *any* experience at all is completely opaque to a beginner.

I tried the code that you suggested and could not make it work. After practicing my black language skills and bruising my forehead, I gave up and went to bed. But I had a thought when I woke this morning: you'd use "show" . . . I'd used that command in a module rather than the userform's VBE. I created a module, inserted the code that you suggested into the module, and it worked first try.

Thank you!

And I annotated this in my "Excel VBA Programming for Dummies" to increase the chance that I'll remember it next time. Now I need to try understanding where VBA expects me to put things.

VERY respectfully,
Larry
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning a string variable to a userform label caption how to have two formats in the Caption style: Label – number - text? Jamal NUMAN Word 39 03-14-2017 06:32 PM
Assigning Form.ActiveControl.Name to variable aramaglia Excel Programming 0 02-10-2017 09:57 AM
Userform label bordercolor not controllable if click label skarden Word VBA 1 09-29-2013 07:27 PM
Assigning a string variable to a userform label caption Custom caption list label lost in a new Word session New Daddy Word 1 09-22-2013 09:21 AM
Custom caption label annoyance zac Word 1 08-29-2010 09:56 AM

Other Forums: Access Forums

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


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