View Single Post
 
Old 08-18-2020, 04:08 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,177
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm not convinced you have this solved yet. Your current code actually populates the same variable (called "EVParty&EVNum") regardless of the actual values in your variables.

You have variables but are using strings of the variable names and expecting the macro to convert the string name of the variable into the variable value. Also, using a space as a separator is useless if either of the variable values contain a space - better to use something that won't appear in the values such as "|"

If you are intending to create a variable based on the values entered by the user in the userform, how are you going to make use of it in the document and/or when reopening the userform? You won't know the name of the variable to go looking for it.

I would recommend a unique location/name for this data location and if you need to store multiple values there then make them all part of a single string with a separator.

For example to write the form info to a variable
Code:
EVParty = PartyTypeList.Value
EVNum = EvidenceID.Value
ActiveDocument.Variables("FormInfo") = EVParty & "|" & EVNum & "|" & "Other stuff"
And to read these values when initialising the form
Code:
Dim sArr() as String
sArr = Split(ActiveDocument.Variables("FormInfo"),"|")
If UBound(sArr) > 1 then
  PartyTypeList.Value = sArr(0)
  EvidenceID.Value = sArr(1)
  MsgBox "Other stuff is: " & sArr(2)
End If
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote