Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Transfer variable to user Form

I have a public variable that I declare at the top of a standard
module. When I run the code to set the variable it appears to be set
and has a value. Then when the form is loaded it forgets the
variable. I am tryign to setup a form to either enter new information
or edit existing information. There will be two buttons on the sheet
to either Add or Edit. If they hit the Edit button I have it set so
they can chose what to edit with an input box as range. This variable
is set to Public so i assumed it woudl carry over to the initialize
part of the user form. Any thoughts?

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Transfer variable to user Form

I'm not real clear about your public variable, whether it's a value or a
Range, but you said range, so for the UserForm Initialize event, try
something like:

Private Sub UserForm_Initialize()
'assumes myPublicVariable is a Range
'and that it's been set up somewhere with
'something like:
' Set myPublicVariable=Sheets(1).Range("A1")

Me!TextBox1 = myPublicVariable.Value
End Sub


"jlclyde" wrote:

I have a public variable that I declare at the top of a standard
module. When I run the code to set the variable it appears to be set
and has a value. Then when the form is loaded it forgets the
variable. I am tryign to setup a form to either enter new information
or edit existing information. There will be two buttons on the sheet
to either Add or Edit. If they hit the Edit button I have it set so
they can chose what to edit with an input box as range. This variable
is set to Public so i assumed it woudl carry over to the initialize
part of the user form. Any thoughts?

Thanks,
Jay
.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Transfer variable to user Form

If you're sure you're initializing that variable somehow, then I'd check to see
if you have a variable that's local to that userform or procedure that is the
same name.

If you have this in a general module:

Public myVar as long
sub Auto_Open()
myVar = 1234
End sub

And you have this in a procedure behind a userform:

Private Sub CommandButton1_Click()
Dim myVar As Long
MsgBox myVar
End Sub

Then the local variable in that _click event will be the one that's used.

========
Another problem while you're in development mode is that you could have ended
any macro by clicking on Run|Reset (in the VBE menus, or hitting the Reset
button on a toolbar). This will erase the values in those public variables.

And if you use "End" to exit any procedure (not End With, End Sub, End
Function--just plain old End), you'll be resetting those public variables.


jlclyde wrote:

I have a public variable that I declare at the top of a standard
module. When I run the code to set the variable it appears to be set
and has a value. Then when the form is loaded it forgets the
variable. I am tryign to setup a form to either enter new information
or edit existing information. There will be two buttons on the sheet
to either Add or Edit. If they hit the Edit button I have it set so
they can chose what to edit with an input box as range. This variable
is set to Public so i assumed it woudl carry over to the initialize
part of the user form. Any thoughts?

Thanks,
Jay


--

Dave Peterson
Reply
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
transfer data from excel form to a spreadsheet Jeff[_11_] Excel Discussion (Misc queries) 0 March 13th 08 05:13 PM
transfer a variable balance from one worksheet to the next cariad 61 New Users to Excel 4 July 31st 07 11:28 PM
How do I fill a cell in a user form from a selection on same form? Terry Tipsy Excel Discussion (Misc queries) 4 June 11th 07 02:59 PM
Transfer Macro to another user Poolpa New Users to Excel 2 March 29th 06 04:15 AM
User defined buttons in Toolbars,transfer to another computer marko Excel Discussion (Misc queries) 2 December 13th 05 07:22 PM


All times are GMT +1. The time now is 12:08 PM.

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

About Us

"It's about Microsoft Excel"