PDA

View Full Version : DocVariables & Multiple Userforms



DavG63
05-08-2016, 12:25 PM
This is a general question about updating DocVariables in a Word document based upon input into various comboboxes in VBA.

My document has a final combobox "OK", which executes the update of all DocVariables based on the values in the Userform. My question is, if for example, I have Userform1, Userform2 and Userform3, all with ComboBoxes 1, 2 & 3 how do I tell the macro which Userform to draw the DocVariable value from? For instance, I'd fill in Userform 1, click the "next" commandbutton and it would "hide.me" Userform1, and call up Userform2, the same with "next" on Userform2, which would call up Userform3.

It's probably either really simple to achieve, or totally impossible. I'm just not sure which.

Would anyone have any suggestions?

Thanks

Dav

gmayor
05-08-2016, 09:13 PM
If the userforms have not been unloaded, then call the userforms by name from a calling macro e.g



Sub Macro1()
Dim oVars As Variables
Set oVars = ActiveDocument.Variables
UserForm1.Show
oVars("varName1").Value = UserForm1.TextBox1.Text
oVars("varName2").Value = UserForm2.TextBox1.Text
oVars("varName3").Value = UserForm3.TextBox1.Text
Unload UserForm1
Unload UserForm2
Unload UserForm3
ActiveDocument.Fields.Update
End Sub


Or you could write the values from each form to uniquely named string variables as you leave the forms and write those variables to the document variables.

However for the type of process you describe, it might be preferable to use a multi-page userform rather than three separate ones?