MS Office Forum / Word / Programming / August 2005
Word 2003 Template issues
|
|
Thread rating:  |
nick.giardelli@gmail.com - 20 Aug 2005 02:43 GMT I will start by thanking everyone that contributes to these news groups. I have learned a lot here.
Now to my question.
I have a word template that I need help with. In this template I have 12 text boxes.
Names of users will go in Textboxes 1-6
An amount will go in textboxes 7-12.
So far this is the easy part.
The part that is kicking my butt is, the amounts have to equal 100. If they do not equal 100 when the user presses the OK button I need a message box to appear with a message telling them there amounts do not equal 100. Now once the user ok's the message box I need the curser to return to textboxes 7-12 and clear the buffer. This is to allow the user to correct there mistake.
Now once they have entered all of there data and it equal's 100, I need
to take that data and place it on a bookmark.
I hope I have not losted anyone.
Thank you for your Time.
Jean-Guy Marcil - 20 Aug 2005 19:36 GMT nick.giardelli@gmail.com was telling us: nick.giardelli@gmail.com nous racontait que :
> I will start by thanking everyone that contributes to these news > groups. I have learned a lot here. [quoted text clipped - 3 lines] > I have a word template that I need help with. In this template I have > 12 text boxes. In the document with "real" textboxes (from the drawing toolbar), ActiveX controls textboxes from the Controls toolbar or textboxes on a userform?
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
nick.giardelli@gmail.com - 21 Aug 2005 08:51 GMT textboxes on a userform
Doug Robbins - 21 Aug 2005 10:13 GMT How about something like:
Option Explicit Dim Bal As Double
Private Sub TextBox8_Enter() If TextBox7 <= 100 Then Bal = (100 - TextBox7) / 5 TextBox8 = Bal TextBox9 = Bal TextBox10 = Bal TextBox11 = Bal TextBox12 = Bal Else MsgBox "You have exceeded the maximum value" TextBox7 = 0 TextBox7.SetFocus End If End Sub Private Sub TextBox9_Enter() Bal = (100 - TextBox7 - TextBox8) / 4 If Bal > 0 Then TextBox9 = Bal TextBox10 = Bal TextBox11 = Bal TextBox12 = Bal Else MsgBox "You have exceeded the maximum value" TextBox8 = 0 TextBox7.SetFocus End If End Sub Private Sub TextBox10_Enter() Bal = (100 - TextBox7 - TextBox8 - TextBox9) / 3 If Bal > 0 Then TextBox10 = Bal TextBox11 = Bal TextBox12 = Bal Else MsgBox "You have exceeded the maximum value" TextBox9 = 0 TextBox7.SetFocus End If End Sub Private Sub TextBox11_Enter() Bal = (100 - TextBox7 - TextBox8 - TextBox9 - TextBox10) / 2 If Bal > 0 Then TextBox11 = Bal TextBox12 = Bal Else MsgBox "You have exceeded the maximum value" TextBox10 = 0 TextBox7.SetFocus End If End Sub Private Sub TextBox12_Enter() Bal = (100 - TextBox7 - TextBox8 - TextBox9 - TextBox10 - TextBox11) If Bal > 0 Then TextBox12 = Bal Else MsgBox "You have exceeded the maximum value" TextBox11 = 0 TextBox7.SetFocus End If End Sub
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
> textboxes on a userform Helmut Weber - 21 Aug 2005 10:14 GMT Hi Nick,
too many questions at once.
To get you started:
Create a blank userform. Add a commandbutton. The commandbutton is therefore the control number 0. Add six textboxes for the names. These will be controls 1 to 6. Add six textboxes for the numbers. These will be controls 7 to 12.
Try the following code with the commandbutton:
Dim lSum As Long ' sum Dim lCnt As Long ' counter lSum = 0 For lCnt = 7 To 12 lSum = lSum + CLng(Me.Controls(lCnt).Text) Next
If lSum <> 100 Then MsgBox "sum <> 100" Me.Controls(7).SetFocus End If
Note that you will get an error, if there is not a number in one of the controls 7 to 12.
By the way this is not a template issue. word.vba.general or the userform-group would be better suited.
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
nick.giardelli@gmail.com - 21 Aug 2005 21:20 GMT Helmut and Doug thanks for your reply
Doug when I tried your code, when I filled in textbox7, it would fill in textbox8 a number of 4 and so on.
Helmut, I tried you version and this is what it looks like
Private Sub CommandButton0_Click()
Dim lSum As Long ' sum Dim lCnt As Long ' counter lSum = 0 For lCnt = 7 To 12 lSum = lSum + CLnt(Me.Controls(lCnt).Text) Next
If lSum <> 100 Then MsgBox "sum <> 100" Me.Controls(7).SetFocus End If
End Sub
This would give me an error on this line on code lSum = lSum + CLnt(Me.Controls(lCnt).Text) Type mismatch (Error 13)
Am I doing something wrong??? I must be
Doug Robbins - 22 Aug 2005 03:42 GMT That was the idea. The use can either accept or change the values.
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
> Helmut and Doug thanks for your reply > [quoted text clipped - 24 lines] > > Am I doing something wrong??? I must be Helmut Weber - 22 Aug 2005 09:08 GMT Hi Nick,
check carefully what is in the textbox, it might be empty or contain something, that cannot be converted into a long number.
Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA "red.sys" & chr(64) & "t-online.de" Word 2002, Windows 2000
nick.giardelli@gmail.com - 26 Aug 2005 15:33 GMT Thanks for your help guys.
I get type mismatch on this here
lSum = lSum + CLng(Me.Controls(lCnt).Text)
This is the code. all I am doing is filling in numbers
Private Sub CommandButton0_Click()
Dim lSum As Long ' sum Dim lCnt As Long ' counter lSum = 0 For lCnt = 7 To 12 lSum = lSum + CLng(Me.Controls(lCnt).Text) Next
If lSum <> 100 Then MsgBox "sum <> 100" Me.Controls(7).SetFocus End If
End Sub
Helmut Weber - 26 Aug 2005 20:24 GMT Hi Nick,
I still maintain, there is something in the textbox, which can't be converted into a long number.
Though my example is right, IMHO, it is pretty hard to debug.
Try to check, what is in the textbox, like this:
>For lCnt = 7 To 12 msgbox "[" & Me.Controls(lCnt).Text & "]"
> lSum = lSum + CLng(Me.Controls(lCnt).Text) >Next And there is the function "IsNumeric", one could use, to find out, whether each character in the textbox represents a number.
To prevent the user from typing anything else then Isnumeric, is a long story.
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
nick.giardelli@gmail.com - 27 Aug 2005 01:33 GMT Not sure what I'm doing wrong, I have tried what your asking me too and it just don't not want to work for me.if you don't mind here is the file.
http://www.njmtechnology.com/files/Client Matter Input Sheet.dot
Helmut Weber - 27 Aug 2005 09:18 GMT Hi Nick,
the controls were not created the way I recommended it, or they werent arranged in the proper way. Step through the code in singlestep mode.
Private Sub CommandButton0_Click()
[snip]
For lCnt = 7 To 12 On Error Resume Next Me.Controls(lCnt).Text = "xxx" & lCnt lSum = lSum + CLng(Me.Controls(lCnt).Text) Next
[snip]
End Sub
This is what you get:
[ ] [xxx10] [ ] [xxx11] [ ] [xxx12] [xxx7 ] [ ] [xxx8 ] [ ] [xxx9 ] [ ]
You see, controls 7 til 9 are in the left column, but should be in the right.
You may use something like:
For lCnt = 1 To 12 Me.Controls(lCnt).Text = Cstr(lCnt) Next
to find out, what control is where.
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
nick.giardelli@gmail.com - 28 Aug 2005 00:05 GMT Helmut, thank you for being Patient with me.
I am very new to this so you might have to hold my hand.
This is what I did from start to finish.
You can email me at nick@njmtechnology.com with you response.
http://www.njmtechnology.com/files/word.doc
Thank you millions
Helmut Weber - 28 Aug 2005 11:53 GMT Hi Nick,
my advice was to create first (!) the commandbutton, and then the textboxes. The purpose of this is to overcome the disadvantages of zero based arrays.
In a zero based array, which is Word's standard, the first element in the array would be element(0). With 12 elements the last one would be element(11). Somewhat confusing.
So, if you create the commandbutton first, it would be control(0), textbox1 would be control(1), textbox12 would be control(12).
>I am very new to this so you might have to hold my hand. I remember well the time, when I didn't know how to insert a floppy disc into a disc drive, as with a square disc, which had two sides, there were 8 possibilities.
lol
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
nick.giardelli@gmail.com - 28 Aug 2005 15:22 GMT I don't understand nor do I get it. I am at a point where I would pay someone for this.
Thanks Helmut.
Doug Robbins - 28 Aug 2005 16:52 GMT As the controls on the form on the website are just named TextBox7 thru TextBox12, just use the following:
Private Sub CommandButton0_Click()
Dim lSum As Long ' sum Dim lCnt As Long ' counter lSum = CLng(TextBox7) + CLng(TextBox8) + CLng(TextBox9) + CLng(TextBox10) + _ CLng(TextBox11) + CLng(TextBox12)
If lSum <> 100 Then MsgBox "sum <> 100" TextBox7.SetFocus End If
End Sub
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
>I don't understand nor do I get it. I am at a point where I would pay > someone for this. > > Thanks Helmut. nick.giardelli@gmail.com - 28 Aug 2005 19:16 GMT Holy Cow, it works. You are the Man Doug.
Doug Robbins - 28 Aug 2005 19:18 GMT BTW, Controls(7) was not one of the controls into which the numeric values were to be entered. It was one of the ones into which the Attorney Initials were to be entered.
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
>I don't understand nor do I get it. I am at a point where I would pay > someone for this. > > Thanks Helmut. Helmut Weber - 28 Aug 2005 19:21 GMT Hi Nick,
have a look at the inbox of you EMail client, if I got your address right.
Don't give up.
Helmut Weber
nick.giardelli@gmail.com - 28 Aug 2005 19:40 GMT You guyz Rock, when I grow up I want to be just like you guyz.
Doug and Helmut. I owe you a beer.
Helmut Weber - 28 Aug 2005 19:55 GMT Hi Nick,
>You guyz Rock, when I grow up I want to be just like you guyz. that brightens my day. Wow!
I'm 55, by the way. And Doug? Not too much difference, I think.
Have a nice day and have a rest, looks like this was a breakthrough.
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
Doug Robbins - 29 Aug 2005 05:02 GMT Add 7.
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
> Hi Nick, > [quoted text clipped - 14 lines] > Win XP, Office 2003 > "red.sys" & Chr$(64) & "t-online.de"
|
|
|