vba form newbie

R

ronaldhawes

I am an experienced Access VBA coder. I have never coded anything i
word. I just want to start my learning easy.

I have a form with a text box "a". The properties specifiy that it i
a 2 digit number. I want to multiply the value in text box "a" by 5 an
put the result on the form in a different location.

Questions:

Do I put the final value in another text box?

How do I reference the value in text box "a"?

How does the form initiate the VB code?

Thank you,
Ro
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Is this a userform (custom dialog) or an in-line form which is a protected
Word document containing formfields.

If the latter, set the properties of the one that you want to display the
result to Calculated and enter the formula which, if the formfield in which
the number is going to be entered has the bookmark name of Text1, will be =
5 * Text1. Set the calculate on Exit property of Text1 so that the
calculation is performed when the user exits that formfield.

If it was a userform, you would use the Exit() event of the control into
which the number is inserted to perform the calculation.


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
P

Peter Hewett

Hi Ron

When a Form loads it calls the UserForm_Initialize event handler (if
present). Other event handlers respond a particular event for their
control. So without getting into the complexities of using a form as a true
class with a user interface you can regard the form as being totally event
driven.

As for you question say you have 2 TextBox controls txtInput and txtResult.

Private Sub txtInput_AfterUpdate()

If IsNumeric(txtInput.Value) Then
txtResult.Value = txtInput.Value * 5
End If
End Sub

The preceeding event handler places the result of the multiplication in the
txtResult control. The event hadler is triggered when the user leaves the
txtInput control.

Find out more info here:
http://word.mvps.org/FAQs/Userforms/index.htm


HTH + Cheers - Peter
 

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