Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

DynamicUpdateCommand

Hello,

Sorry if this has been asked before but I am having a problem with the DynamicUpdateCommand,

I am trying to update a field called value to it's value + 1, eventually it will be more complicated than this but I cannot get even this basic operation to work.

My code inside a macro is:

sub Update

set result1 = ActiveDocument.DynamicUpdateCommand ("UPDATE * SET Value = Value + 1 Where IDVal = 'CC_145'")

End Sub

this does nothing, however if I remove the Value + parts it does update to 1:

sub Update

set result1 = ActiveDocument.DynamicUpdateCommand ("UPDATE * SET Value = 1 Where IDVal = 'CC_145'")

End Sub

The above does work does not achieve what we need.

Any help would be great!

Many Thanks,
Chris

1 Solution

Accepted Solutions
nstefaniuk
Creator III
Creator III

Hi. Try with this module :

sub increaseValue

vChosenId = ActiveDocument.GetVariable("vChosenId").GetContent.String

vChosenIdValue = CInt(ActiveDocument.GetVariable("vChosenIdValue").GetContent.String)

query="UPDATE Data SET value = "&vChosenIdValue+1&" Where id = '"&vChosenId&"'"

set sqlerror=ActiveDocument.DynamicUpdateCommand(query)

if (sqlerror = false) then ' send message when error

MsgBox sqlerror.ErrorMessage

exit sub

end if

end sub

And create 2 variables : 1 which store the chosen id and 1 which store the value for the chosen id (easy to create with function Only and a Set Analysis)

View solution in original post

4 Replies
IAMDV
Luminary Alumni
Luminary Alumni

Hi Chris,

Which version of QV are you using? Please can you post the sample document? It will be easy for me to test.

Thanks - DV

www.qlikshare.com

Not applicable
Author

Hi DV,

Thanks for your reply. I have added my development file to the question.

I am using QV 10 SR3.

Thanks again for any help you can offer,

Chris

Not applicable
Author

Hi,

I wondered if anyone could help with this and I am still confused as to what I am doing wrong?

Thanks!

Chris

nstefaniuk
Creator III
Creator III

Hi. Try with this module :

sub increaseValue

vChosenId = ActiveDocument.GetVariable("vChosenId").GetContent.String

vChosenIdValue = CInt(ActiveDocument.GetVariable("vChosenIdValue").GetContent.String)

query="UPDATE Data SET value = "&vChosenIdValue+1&" Where id = '"&vChosenId&"'"

set sqlerror=ActiveDocument.DynamicUpdateCommand(query)

if (sqlerror = false) then ' send message when error

MsgBox sqlerror.ErrorMessage

exit sub

end if

end sub

And create 2 variables : 1 which store the chosen id and 1 which store the value for the chosen id (easy to create with function Only and a Set Analysis)