Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Does anyone know why variables lose their contents? e.g. I have a variable which has a formula
=' Email : ' & EmailAddress
I have a macro (launched via a button) which uses the content of this variable. For some reason the contents of the variable gets cleared and the formula is lost.
What I eventually did was to delete the bookmarks I was using.
Then fill in the formula's I needed in the variables.
Then create the bookmarks again
Activate the new bookmarks via the buttons.
This for the time being seems to have stopped the formulas from being deleted from the variables
Hi MarkBoomer.
I don't know how you declared your variable, and the variable behaves differently depending on how it was declared.
LET variable1 = something;
vs.
SET variable2 = something else;
LET variables are first evaluated, then the evaluated expression is stored into the variable.
SET variables: The expression itself is stored in the variable and behaves like a dynamic variable which gets updated when for example your selections change.
Try and always declare variables in the script, not in the GUI variable overview.
Hope this helps.
Kind regards
BI Consultant
Magus
I should have mentioned the variables are created in
SETTINGS | DOCUMENT PROPERTIES | Variables Tab
Then I enter the formula in the value field.
I select a row in a table and have a button which executes a macro which retrieves the value of the variable and then uses it to fill in the email address in an email in Outlook. I do it this way as I couldn't find a way to directly enter QlikView fields into macros.
Hi again MarkBoomer.
Here are some macro code examples on how to get/set fields/variable content:
GetVariableValue:
SET vMacroVar = ActiveDocument.Variables("NameOfDocumentVariable")
vMacroVar.GetContent.String
SetVariableValue:
SET vMacroVar = ActiveDocument.Variables("NameOfDocumentVariable")
vMacroVar.SetContent "ValueToSet", True
GetFieldValue:
ActiveDocument.Fields("FieldName").GetSelectedValues.Item(0).Text
SetFieldValue:
ActiveDocument.Fields("FieldName").select "ValueToSet"
Kind regards
BI Consultant
Magnus
Thats similar to what I'm using in the macro to get the value of the variable. The problem is that the variable is set already in the Document settings and the macro retrieves the value.
The problem is that by the time the macro retrieves the variable the contents (i.e. the formula which creates the value) has been cleared.
What I eventually did was to delete the bookmarks I was using.
Then fill in the formula's I needed in the variables.
Then create the bookmarks again
Activate the new bookmarks via the buttons.
This for the time being seems to have stopped the formulas from being deleted from the variables