Solved

vba - UserFrom with textbox

Posted on 2011-09-18
3
259 Views
Last Modified: 2012-05-12
Hello Experts,

I have a Userform that is composed of 4 textboxes - Each textbox is named Manager1, Manager2 etc. My data is on sheet("INFO"). I am having problems getting it to initiliaze.  Can you tell me where I am making my error.  Thanks.

Here is my code:

---------------------------------------

Private Sub UserForm_Initialize()
 
   Dim i As Integer
   Dim ctl As Control
   
   i = 1
   For Each ctl In UserForm1
      If textbox.Name = "Manager" & i Then
         textbox.text = Worksheets("INFO").Range("A" & i + 1).Value
         i = i + 1
      End If
   Next
   
End Sub
0
Comment
Question by:mike637
3 Comments
 
LVL 6

Expert Comment

by:bartvd
ID: 36556448
You need to change textbox in ctl
0
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
ID: 36556449
Why is the variable named ctl in your for each-statement and textbox when you use it inside the loop?
But this won't work reliable if for each iterates through the controls in wrong order. You can try this
   For Each ctl In UserForm1.Controls
      If left(ctl.Name, 7) = "Manager" Then
         ctl.Text = Worksheets("INFO").Range("A" & (Mid(ctl.Name, 8) + 1)).Value
      End If
   Next

Open in new window

Maybe you need Mid(ctl.Name, 7) instead of 8, not sure about VBA
0
 

Author Closing Comment

by:mike637
ID: 36556482
Thanks for the guidance!!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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