Userform with math formulas

C

call_me_sol

Hi -

I need to create a very simple user form with a text box so that user
can enter a value that box to be used to complete very simple math
equations:

Crude example:
User enters: X
Userform will calculate: (X*1000)+6 = Y
Userform will then calculate: Y*4 = 8024
Userform will then paste the values ('2006' and '4012') into the
document in the appropriate spots (using doc variables that I already
know how to do)

So, really, my only question is how to make formulas work using VBA.

TIA!

-sol
 
G

Greg Maxey

Something like this:
Private Sub CommandButton1_Click()
Dim oVar1 As Variable
Dim oVar2 As Variable
Dim x As Double
Dim y As Double
Dim z As Double
x = Me.TextBox1.Value
y = (x * 2000) + 6
z = y * 4
ActiveDocument.Variables("oVar1").Value = y
ActiveDocument.Variables("oVar2").Value = z
Me.hide
End Sub
 
C

call_me_sol

THANKS A LOT!!! That worked like a charm!

Last question -

I've never done this before. I want to add a pull down menu in which
I will have three or four predefined (non-changing) choices. Do I use
a list box or a combo box? How do I code the contents of the box?
Finally, how can I associate the dropdown choices with a DocVariable?

Thanks again!
 
G

Greg Maxey

Private Sub CommandButton1_Click()
Dim oVar As Variable
Set oVar = ActiveDocument.Variables("oVar")
oVar.Value = Me.ListBox1.Text
Me.Hide
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.AddItem "Item 1"
.AddItem "Item 2"
End With
End Sub
 

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