Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel UserForm

Status
Not open for further replies.

vestax22

Programmer
Jun 18, 2003
139
CA
Hi,

I launch a form from an Excel worksheet. This form contains textboxes that are linked to the worksheet by the controlsource property.

First of all every time the User Form is loaded I clear the range that is linked to the user form so that the text boxes point to blanks. Now here is my problem...

On form initialise I have code that initialises these text boxes because I want them to have default values. It's very simple code. Ex.

txtDolomiteFactor = "0.03"
txtDolomiteMoist = "5.89"

When the userform loads I only the first textbox given a value will show this value. In the case above txtDolomiteFactor will contain 0.03 but txtDolomiteMoist will contain Blank.

Could anybody help me out??
 
Hi vestax22,

I'm guessing that txtDolomiteFactor is the first control on your form which is how it manages to work when really neither assignment ought to. You need to qualify the control names with the form - if you're in form code then qualification of Me will do it.

Code:
Me.txtDolomiteFactor = "0.03"
Me.txtDolomiteMoist = "5.89"

Enjoy,
Tony
 
It still doesn't work


I could put the first line in commentary and the form will show the second line Ex:

'Me.txtDolomiteFactor = "0.03"
Me.txtDolomiteMoist = "5.89"


Well txtDolomiteMoist textbox will have 5.89 inside it.
Its as if the program doesn't refresh or something.

Any help would be appreciated thx
 
Sounds like you are trying to set the text boxes from the macro. You can do it in a couple of ways, but don't mix and match:

Method 1:
Assuming the control source cells are A1 and A2:
Code module:[blue]
Code:
       Sub test()
         [A1] = 0.03
         [A2] = 5.89
         UserForm1.Show
       End Sub
[/color]


Method 2:
Code module:[blue]
Code:
       Sub test()
         UserForm1.Show
       End Sub
[/color]

Form code:[blue]
Code:
       Private Sub UserForm_Activate()
         txtDolomiteFactor = "0.03"
         txtDolomiteMoist = "5.89"
       End Sub
[/color]

 
Thx for the replys guys. It doesn't work though.

Zathras The first method you described works and it proves that you understand my problem because there are two ways to do this. I want to you the second way where I don't touch the control source cells. I tried to give the textboxes values inside the userform's activate event that you described and it does the same thing.

It only shows the first textbox I affected with a value.

Any other ideas?

Thx
 
Interesting. Try this:
[blue]
Code:
Private Sub UserForm_Activate()
  txtDolomiteMoist.SetFocus
  txtDolomiteMoist = 5.89
  txtDolomiteFactor.SetFocus
  txtDolomiteFactor = 0.03
End Sub
[/color]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top