LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Textbox in Userform not recognised by Module

From a programmer's perspective, if your sub procedure requires a
value or an object then pass it in as a parameter. Give you're sub
procedure an argument. If your sub procedure just needs the text, pass
in the text e.g.

Public Sub MyMacro(ByVal Text As String)
' <Do something with Text here
End Sub

Private Sub cmdRun_Click()
MyMacro txtTest.Text
End Sub

However, if your sub procedure needs to operates on the textbox object
itself, then use the textbox as the argument (i.e. pass a pointer to
the textbox) e.g.

Public Sub MyMacro(ByVal oTextBox As MSForms.TextBox)
' <Do something with oTextBox here
End Sub

Private Sub cmdRun_Click()
MyMacro txtTest
End Sub

--

Rich J wrote in message ...
The Modules don't recognize the controls on a Userform. There are several things you can do.

1) Put the MyMacro code in the Userform code.
or
2) Pick a cell on the worksheet to pass the value to. Then pick it up from sheet in MyMacro

Private Sub txtTest_Change() Instead of this sub you could also set the ControlSource for
range("A1") = txtTest.value the textbox in the userform to a particular cell in the worksheet.
End Sub Just put A1 in the controlsource line in the properties window.

Sub MyMacro()
Dim strTest as String
strTest = range("A1")
.
.

3) Probably the best way is to add the variable to your macro name
This assumes MyMacro is on Module1

Sub MyMacro (str)
strTest = str
end sub

' The code on your userform could look like this
Private Sub cmdRun_Click()
Dim Temp as string
Temp = txtTest.value
If Temp < vbNullString then ' This would not let the macro to be called if the textbox was empty
Module1.MyMacro Temp ' If you add the variable to the macro name on Module1 then as soon
end if ' as you type ' Module1. ' on the userform code, you should see a window open
End Sub ' with MyMacro as a choice. Then when you add that and have Module1.MyMacro
' you should see str meaning that a value needs to be in the line. Temp will
' pass the value to str

I hope I'm being clear for you. I'm not a programmer but I've been doing a lot with Userforms

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass values from a userform to a standard module? TBA[_2_] Excel Programming 3 January 7th 04 01:50 PM
Passing variables from module to userform Chris Dunigan Excel Programming 4 November 26th 03 09:37 AM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM
Userform with template class module problem Tom Ogilvy Excel Programming 0 July 17th 03 06:38 PM
Delete userform/module using VB Rohit Thomas Excel Programming 5 July 16th 03 11:01 PM


All times are GMT +1. The time now is 07:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"