Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to produce a multiple field prompt box to enter info in WORD?

Status
Not open for further replies.

JGKWORK

IS-IT--Management
Apr 1, 2003
342
GB
Hi,

Can someone help, I have a Word template at work that has been set-up by someone who has long since left my company. When starting up the template a single popup box (fairly large) appears with several fields in which you can enter info into, after entering the info and clicking OK, the info is displayed on the word doc itself. I have learned about "fields" and used the "Fillin" & "Ask" fields to do this, but they appear as individual prompt boxes for each field.

My question is how do I generate a prompt box to enter info in to my document that contains SEVERAL fields?

The doc also contains a macro, but don't understand the code..

Many thanks.
 
Hi, I have looked at this again and it seems that the MACRO is generating the form (with multiple fields) question is, can someone tell if this code (below) is hand written or has been generated through a wizard in Word (if its the latter, can someone tell me which wizard?) MANY thanks!

Code:


Public Sub MAIN()
Dim Displayed
Dim AcNo$
Dim add1$
Dim add2$
Dim add3$
Dim add4$
Dim Name_$
Dim Title$
Dim Clerk$
Dim Atext1$
Dim Atext2$
Dim Atext3$
Dim Atext4$
Dim Atext5$
Dim A1$
Dim A2$
Dim A3$
Dim A4$
Dim A5$
Dim Test$
'Note ammendments made to add 3rd address line 09/07/97 by PKS
On Error GoTo -1: 'On Error GoTo ErrorHandler
WordBasic.BeginDialog 426, 342, "Input Customer Details"
WordBasic.GroupBox 10, 6, 405, 288, "Please Enter "
WordBasic.Text 152, 197, 35, 13, "Text", "Text16"
WordBasic.Text 23, 173, 76, 13, "Address 3", "Text17"
WordBasic.Text 164, 263, 21, 13, "#1", "Text11"
WordBasic.Text 218, 263, 21, 13, "#2", "Text12"
WordBasic.Text 270, 263, 21, 13, "#3", "Text13"
WordBasic.Text 324, 263, 21, 13, "#4", "Text14"
WordBasic.Text 376, 263, 21, 13, "#5", "Text15"
WordBasic.Text 204, 278, 156, 13, "Insert 4 digit number", "Text10"
WordBasic.Text 24, 218, 40, 18, "Clerk", "Text6"
WordBasic.Text 24, 241, 112, 18, "Para Selection", "Text8"
WordBasic.Text 23, 35, 96, 13, "Account No.", "Text5"
WordBasic.Text 23, 59, 35, 18, "Title", "Text4"
WordBasic.Text 23, 81, 75, 18, "Forename", "Text1"
WordBasic.Text 23, 104, 67, 18, "Surname", "Text2"
WordBasic.Text 23, 127, 67, 18, "Address ", "Text7"
WordBasic.Text 23, 150, 76, 18, "Address2 ", "Text9"
WordBasic.Text 24, 196, 84, 18, "Post Code ", "Text3"
WordBasic.TextBox 150, 35, 170, 18, "AccountNo"
WordBasic.TextBox 150, 58, 46, 18, "Title" 'Title
WordBasic.TextBox 150, 81, 170, 18, "FNAME"
WordBasic.TextBox 150, 104, 170, 18, "SNAME"
WordBasic.TextBox 150, 127, 222, 18, "ADD1" 'Street Name
WordBasic.TextBox 150, 150, 222, 18, "ADD2" 'Town
WordBasic.TextBox 150, 173, 222, 18, "ADD3" '3rd Address Line
WordBasic.TextBox 151, 196, 222, 18, "ADD4" 'Post Code
WordBasic.TextBox 151, 218, 170, 18, "Clerk" 'Author / Typist
WordBasic.TextBox 151, 241, 48, 18, "Atext1"
WordBasic.TextBox 205, 241, 48, 18, "Atext2"
WordBasic.TextBox 257, 241, 48, 18, "Atext3"
WordBasic.TextBox 309, 241, 48, 18, "Atext4"
WordBasic.TextBox 361, 241, 48, 18, "Atext5"
WordBasic.OKButton 51, 304, 149, 31
WordBasic.CancelButton 227, 305, 149, 31
WordBasic.EndDialog

Dim Dlg As Object: Set Dlg = WordBasic.CurValues.UserDialog
Dlg.Clerk = ""
Dlg.Title = ""
Dlg.add4 = ""
Dlg.add3 = ""
Dlg.add2 = ""
Dlg.add1 = ""
Dlg.SNAME = ""
Dlg.FNAME = ""
Dlg.AccountNo = ""


Displayed = 1

DisplayDialog:
On Error GoTo -1: On Error GoTo Bye
WordBasic.Dialog.UserDialog Dlg
On Error GoTo -1: On Error GoTo 0
'*************************************************
'Assign bookmark fields with contents of form
'*************************************************

AcNo$ = Dlg.AccountNo
add1$ = Dlg.add1
add2$ = Dlg.add2
add3$ = Dlg.add3
add4$ = Dlg.add4
Name_$ = Dlg.Title + " " + Dlg.FNAME + " " + Dlg.SNAME
Title$ = Dlg.Title + " " + Dlg.SNAME
Clerk$ = Dlg.Clerk
Atext1$ = Dlg.Atext1
Atext2$ = Dlg.Atext2
Atext3$ = Dlg.Atext3
Atext4$ = Dlg.Atext4
Atext5$ = Dlg.Atext5

' ****************************************************
' Error Checks AutoText Variable for Null Values, Get corresponding
' AutoText for all ATEXT Variables. Unknown AutoText variables are
' error trapped.
' ****************************************************

If Atext1$ = "" Then GoTo atxt2
A1$ = WordBasic.[GetAutoText$](Atext1$, 1)
If A1$ = "" Then GoTo Error1

atxt2:
If Atext2$ = "" Then GoTo atxt3
A2$ = WordBasic.[GetAutoText$](Atext2$, 1)
If A2$ = "" Then GoTo Error2

atxt3:
If Atext3$ = "" Then GoTo atxt4
A3$ = WordBasic.[GetAutoText$](Atext3$, 1)
If A3$ = "" Then GoTo Error3

atxt4:
If Atext4$ = "" Then GoTo atxt5
A4$ = WordBasic.[GetAutoText$](Atext4$, 1)
If A4$ = "" Then GoTo Error4

atxt5:
If Atext5$ = "" Then GoTo Clerk_
A5$ = WordBasic.[GetAutoText$](Atext5$, 1)
If A5$ = "" Then GoTo Error5

Clerk_:
Rem MsgBox "clerk=" + clerk$
If Clerk$ = "" Then
Test$ = WordBasic.[GetAutoText$]("990", 1)
Rem MsgBox test$
Else
Test$ = WordBasic.[GetAutoText$]("991", 1)
Rem MsgBox test$
End If
AddText:

' **************************************************
' Move Captured Address Data to Bookmark Locations
' **************************************************
WordBasic.WW7_EditGoTo Destination:="add1"
WordBasic.Insert add1$
WordBasic.WW7_EditGoTo Destination:="add2"
WordBasic.Insert add2$
WordBasic.WW7_EditGoTo Destination:="add3"
WordBasic.Insert add3$
WordBasic.WW7_EditGoTo Destination:="add4"
WordBasic.Insert add4$
WordBasic.WW7_EditGoTo Destination:="Name"
WordBasic.Insert Name_$
WordBasic.WW7_EditGoTo Destination:="Salutation"
WordBasic.Insert Title$
WordBasic.WW7_EditGoTo Destination:="AcNo"
WordBasic.Insert AcNo$
Rem LineDown 2


' ****************************************************
' Error Checks AutoText Variable for Null Values, Get corresponding
' AutoText and Inserts Paragraph then returns twice. Null AutoText
' variables are ignored and pass too the next autotext variable.
' error trapped.
' ****************************************************
If Test$ <> "" Then
WordBasic.WW7_EditGoTo Destination:="LetterEnd"
WordBasic.Insert Test$
WordBasic.LineUp 1
WordBasic.Insert Clerk$
Else
WordBasic.WW7_EditGoTo Destination:="LetterEnd"
WordBasic.Insert Test$
End If
WordBasic.WW7_EditGoTo Destination:="AcNo"
WordBasic.LineDown 2
WordBasic.StartOfLine
If A1$ <> "" Then
WordBasic.Insert A1$
WordBasic.InsertPara
End If
If A2$ <> "" Then
WordBasic.Insert A2$
WordBasic.InsertPara
End If
If A3$ <> "" Then
WordBasic.Insert A3$
WordBasic.InsertPara
End If
If A4$ <> "" Then
WordBasic.Insert A4$
WordBasic.InsertPara
End If
If A5$ <> "" Then
WordBasic.Insert A5$
WordBasic.InsertPara
WordBasic.InsertPara
End If
GoTo Bye

' ***************************************************************
'Error Handling Routine
' ***************************************************************
Error1: WordBasic.MsgBox "Invalid Paragraph No, Input Correct Paragraph No.", "ERROR IN PARAGRAPH BOX #1", 48
GoTo DisplayDialog

Error2: WordBasic.MsgBox "Invalid Paragraph No, Input Correct Paragraph No.", "ERROR IN PARAGRAPH BOX #2", 48
GoTo DisplayDialog

Error3: WordBasic.MsgBox "Invalid Paragraph No, Input Correct Paragraph No.", "ERROR IN PARAGRAPH BOX #3", 48
GoTo DisplayDialog

Error4: WordBasic.MsgBox "Invalid Paragraph No, Input Correct Paragraph No.", "Error In Paragraph Box #4", 48
GoTo DisplayDialog

Error5: WordBasic.MsgBox "Invalid Paragraph No, Input Correct Paragraph No.", "ERROR IN PARAGRAPH BOX #5", 48
GoTo DisplayDialog

Bye:
WordBasic.MsgBox "Ammendments can now be made, all (INSERTS) are to be filled manually", "Correspondence Standard Letters", 48
End Sub
 
Hi,

Your macro code is in Wordbasic, rather than Visual basic for Applications (vba), which suggests that it may have been written using Word 6. The amendments from 1997 would seem to confirm this, though vba was implemented in Word by that time.

The presence of the DIM statements suggests the code was hand-written, rather than being developed via a macro recorder.

I don't know enough about Wordbasic to help modify this code. Hopefully someone else here does.

Cheers
 
Thanks very much, that helps alot, I think I'll be able to modify it, just wanted to know where it had come from and how it was generated.
 
The code is definitely WordBasic. It displays a custom dialog/input box to collect data then dumps that into fields.

What OS and version of Word are you running?

To answer your question, in my opinion, the best way to gather information that will be placed into several fields is similar to the code you posted. However with newer versions, this would be done with a UserForm that collates user inputs, error traps the inputs to make sure they are correct, prompts the user if incorrect, and when complete fills in the appropriate locations with the information.

UserForms are reasonably easy to create and to get going. As you can see from the extent of the code, trapping errors is (and is normally) the most difficult and time consuming part.

I have a (very) simple sample file that I use to demonstrate the ability to use UserForms for data gathering, and inserting that information into bookmarks. This is pretty much what the code you posted does. Mines use VBA rather than WordBasic. I use it for teaching an intermediate/advanced Word course for our users. If you would like a copy, post where I could send it. I am swamped a bit right now, so I don't think I could send it until next week. Just remember, this file is both fairly simple, and does not cover any in-depth use of the VBA Editor. I don't know if it would help. On the other hand, there are some excellent FAQ on this site, Help in the VBA Editor is pretty good, and MSDN covers a lot of topics, and there are plenty of good books on VBA as well.



Gerry
 
fumei,

Can I get a copy of that userform sample you have? This is exactly what we've been looking for.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top