Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Assigning Variable value to Fields

Hi,

I have an input box in which a user enters a date field which is linked to variable "Inputdate". On clicking a button 2 different date fields use this value for selection. In addition I require extra selection criteria to limit the type of records.

The following code is used

Sub DateValues

Set q = ActiveDocument
q.ClearAll (false)

udf=q.Variables("InputDate").GetContent.String

Set d1 = ActiveDocument.Fields("DATE1")
Set d2 = ActiveDocument.Fields("DATE2")
Set type = ActiveDocument.Fields("RECORD_TYPE")

d1.Select "*" & udf & "*"
d2.Select "*" & udf & "*"
type.Select "NEW*"

end sub

However only the type Selection criteria is activated - dates are ignored. Also if I try to use "=" with date variables selection is not applied correctly.

Could you please let me know if you can see any obvious error ?

Thanks

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The mismatch between the variable type and the date is usually the problem. My suggestion for a generic approach to the problem --. always convert to date() type before selecting.

seldate = ActiveDocument.Evaluate("date(date#(vDate))")
ActiveDocument.GetField("DateField").Select(seldate)


The attached qvw has an example.

-Rob

View solution in original post

7 Replies
manishkumar75
Partner - Creator II
Partner - Creator II

Hi,

Try to change variable name "type" to some other name.

- Manish

Not applicable
Author

Thanks for the reply Manish

I have used different names but does not seemt to resolve issue

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

could be something to do with the date format vs. numeric format. You can test what strings are you getting back from your variables (insert some msgbox statements for testing) and see whether it's what you are expecting.

Oleg

Ask me about Qlik Sense Expert Class!
Not applicable
Author

I got a macro parse error on the "set type = " field. That needs to be changed as it's probably a reserved word.

I had to fiddle with the data and user entry a bit, but I was able to get your sub working. It probably has to do with the format of your date fields. Have your tried a less specific entry? All of my dates are followed by 12:00:00 AM, so when I set the variable to "12", everything is selected. When I set the variable to "5/" I get everything in March or anything on the fifth day of the month.

In your macro, you're not comparing a date to a date, but rather a date to a string that resembles a date. Therefore, if the user enters 5/1/09, but your data says 05/01/2009, then you're not going to get any matches.

Not applicable
Author

Check if WaitForIdle() function helps. Sometimes after making selections, you should use it before proceeding further, otherwise you get erratic results.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The mismatch between the variable type and the date is usually the problem. My suggestion for a generic approach to the problem --. always convert to date() type before selecting.

seldate = ActiveDocument.Evaluate("date(date#(vDate))")
ActiveDocument.GetField("DateField").Select(seldate)


The attached qvw has an example.

-Rob

Not applicable
Author

Thanks - Formatting date seems to have resolved issue