Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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!
Any help?
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!
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
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!
No, no works, I'm sorry
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.
Muchas Gracias
Many Thank's
I will look your example and revise my data
Your example runs perfectly, but I copy the same in my file and don't run.
Can you see them
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!