I am currently creating an order form for users to fill out.
For that I have created several form fields in a Word document.
For me to make sure that users will fill the appropriate fields, I have created a macro. I succeeded in making a macro that will force the user to enter something in a pop-up box (this is the first "do"-string.
However I want the view to jump to the given field, which is what I am trying to do in the second "do"-string.
This is the code:
Sub mustFill()
Dim fieldvars(1 To 12) As String
Dim labels(1 To 12) As String
fieldvars(1) = "siteName"
fieldvars(2) = "currentDate"
fieldvars(3) = "deliveryDate"
fieldvars(4) = "pcpName"
fieldvars(5) = "pcpMail"
fieldvars(6) = "pcpPhone"
fieldvars(7) = "numberOfTurbines"
fieldvars(8) = "siteAddress"
fieldvars(9) = "emergencyPhone"
fieldvars(10) = "hubHeight"
fieldvars(11) = "towerSections"
fieldvars(12) = "coordinateSystem"
labels(1) = "Site name"
labels(2) = "Current date"
labels(3) = "Requested delivery date"
labels(4) = "Project contact person, Name"
labels(5) = "Project contact person, E-mail"
labels(6) = "Project contact person, Phone no."
labels(7) = "Number of turbines"
labels(8) = "Site address"
labels(9) = "Emergency phone no."
labels(10) = "Hub height"
labels(11) = "Number of tower sections"
labels(12) = "Turbine coordinate system, datum and zone"
For i = 1 To 12
If ActiveDocument.FormFields(fieldvars(i)).Result = "" Then
Do
sInFld = InputBox("This field: " & labels(i) & " is mandatory. Please fill in below.")
Do
ActiveDocument.FormFields(fieldvars(i)).SetFocus
Loop While sInFld = ""
Loop While sInFld = ""
ActiveDocument.FormFields(fieldvars(i)).Result = sInFld
End If
Next i
End Sub
Is it the string that I have done wrong or is it a problem with multiple "Do"-strings inside the "If"-formula.
Thank you a lot in advance!
/thormann
Aucun commentaire:
Enregistrer un commentaire