Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
ecolomer
Master II
Master II

Macro don't work properly

I have a macro that works well in a QV file but not in other.

The macro in question is:

sub InLote

  SelVal=ActiveDocument.Evaluate("=getFieldSelections(NumPedido, ';', 25)")

  NReg=ActiveDocument.Evaluate("=getSelectedCount(NumPedido)")

  for k = 1 to NReg

     InValue = ActiveDocument.Evaluate("=Subfield(SelVal, ';' ,"&k&")")

      ActiveDocument.GetApplication.Sleep 100

      ActiveDocument.DynamicUpdateCommand("UPDATE LOTE SET LoteFab=$(vLote) WHERE NumPedido="&InValue&"")

      ActiveDocument.GetApplication.Sleep 100

  next

end sub

The statement that it is not running: is marked in blod. But in other QV the same statement work's perfectly

Any help

TX

1 Solution

Accepted Solutions
jerem1234
Specialist II
Specialist II

What is happening is that SelVal is not a field/variable in your application. So for example you can do 3 things:

1. Add the variable SelVal into your qvw (Variable Overview...) and use the expression in the variable as =getFieldSelections(NumPedido, ';', 25) and then use:

InValue = ActiveDocument.Evaluate("=Subfield(SelVal, ';' ,"&k&")")


2. Return the text part of your variable SelVal in the vbscript and enclose with quotes:

InValue = ActiveDocument.Evaluate("=Subfield(" & chr(39) &SelVal & chr(39) & ", ';' ," & k & ")")

3. Or you can just evaluate the getfieldselections in the same statement like:

InValue = ActiveDocument.Evaluate("=Subfield(getFieldSelections(NumPedido, ';', 25), ';' ," & k & ")")

Hope this helps!

View solution in original post

12 Replies
ecolomer
Master II
Master II
Author

Any help?

jerem1234
Specialist II
Specialist II

What is happening is that SelVal is not a field/variable in your application. So for example you can do 3 things:

1. Add the variable SelVal into your qvw (Variable Overview...) and use the expression in the variable as =getFieldSelections(NumPedido, ';', 25) and then use:

InValue = ActiveDocument.Evaluate("=Subfield(SelVal, ';' ,"&k&")")


2. Return the text part of your variable SelVal in the vbscript and enclose with quotes:

InValue = ActiveDocument.Evaluate("=Subfield(" & chr(39) &SelVal & chr(39) & ", ';' ," & k & ")")

3. Or you can just evaluate the getfieldselections in the same statement like:

InValue = ActiveDocument.Evaluate("=Subfield(getFieldSelections(NumPedido, ';', 25), ';' ," & k & ")")

Hope this helps!

View solution in original post

ecolomer
Master II
Master II
Author

Yes is good, but now in the expression:

ActiveDocument.DynamicUpdateCommand("UPDATE LOTE SET LoteFab=$(vLote) WHERE NumPedido="&InValue&"")


no works properly ¿¿??  any idea??


vLote are a Variable defined in the QV and used in a input mode

jerem1234
Specialist II
Specialist II

Try something like:

ActiveDocument.DynamicUpdateCommand("UPDATE LOTE SET LoteFab='$(vLote)' WHERE NumPedido='" &InValue & "'")

In case you don't see it, i've enclosed InValue with single quotes, as well as $(vLote). If you are expecting string values coming through, you need single quotes so it knows they are text.

Hope this helps!

ecolomer
Master II
Master II
Author

No, no works, I'm sorry

jerem1234
Specialist II
Specialist II

Hmm. I've attached below an example I have that pretty much uses the same code you have. Maybe you can take a look and see if there might be something wrong with the data you are using.

ecolomer
Master II
Master II
Author

Muchas Gracias

Many Thank's

I will look your example and revise my data

ecolomer
Master II
Master II
Author

Your example runs perfectly, but I copy the same in my file and don't run.

Can you see them

jerem1234
Specialist II
Specialist II

Ah you have an extra space in your table name:

sub InLote

  SelVal=ActiveDocument.Evaluate("=getFieldSelections(NumPedido, ';', 25)")

  NReg=ActiveDocument.Evaluate("=getSelectedCount(NumPedido)")

  for k = 1 to NReg

  InValue = ActiveDocument.Evaluate("=Subfield(SelVal, ';' ,"&k&")")

  ActiveDocument.GetApplication.Sleep 100

  ActiveDocument.DynamicUpdateCommand("UPDATE F_ LOTE  SET  LoteFab='$(vLote)' WHERE NumPedido='" &InValue & "'")

  ActiveDocument.GetApplication.Sleep 100

  next

end sub

Delete that space, and that should get it working:

sub InLote

  SelVal=ActiveDocument.Evaluate("=getFieldSelections(NumPedido, ';', 25)")

  NReg=ActiveDocument.Evaluate("=getSelectedCount(NumPedido)")

  for k = 1 to NReg

  InValue = ActiveDocument.Evaluate("=Subfield(SelVal, ';' ,"&k&")")

  ActiveDocument.GetApplication.Sleep 100

  ActiveDocument.DynamicUpdateCommand("UPDATE F_LOTE  SET  LoteFab='$(vLote)' WHERE NumPedido='" &InValue & "'")

  ActiveDocument.GetApplication.Sleep 100

  next

end sub

Hope this helps!