Variables From TextBoxes

S

SeanEvans

I am trying to capture a variant using a TextBox for use later on in
seperate Macro. The first part of the macro works fine and captures th
data I require but it seems to lose the variable later on.

I use a Form with 3 TextBoxes to capture 3 dates - date1, date2, date3
Upon clicking the OK button (CommandButton1) the contents of th
textboxes are "transfered" to variables date1, date2, date3 - as see
below.


Public Sub CommandButton1_Click()
Dim date1, date2, date3 As Variant

date1 = TextBox1
date2 = TextBox2
date3 = TextBox3

Unload UserForm1


End Sub

Then I wish to run the following code to return these dates vi
keypresses no data is returned.

Sub Fkeyson()

Application.OnKey "{F10}", "doDate1"
Application.OnKey "{F11}", "doDate2"
Application.OnKey "{F12}", "doDate3"

End Sub

Sub Fkeysoff()

Application.OnKey "{F10}"
Application.OnKey "{F11}"
Application.OnKey "{F12}"
End Sub

Sub doDate1()

MsgBox (date1)
ActiveCell.Value = date1

End Sub

What do I need to do to carry the variables over from one macro t
another ?

Thanks in advance
 
T

Tom Ogilvy

in a general module (the type you would get if you did Insert=>Module) at
the very top, outside any procedure put in

Public Date1 as Variant, Date2 as Variant, Date3 as Variant

or just
Public Date1, Date2, Date3

then change you click event to this

Public Sub CommandButton1_Click()

date1 = TextBox1
date2 = TextBox2
date3 = TextBox3

Unload UserForm1


End Sub

And don't declare the date variables anywhere else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top