I am trying to use the @script function but with no luck. It runs the script but instead of returning a value the data provider does not refresh.
In the report I have:
SELECT …
FROM …
WHERE
FOO = @Script(‘myString’,‘A’,'myProc)
My VBA code is:
Sub myProc()
Dim doc As Document
Dim myString As String
Set Document = ActiveDocument
myString = Environ(“USERNAME”)
End Sub
I have simplified the code as much as possible. I realize that there are other ways to get the particular USERNAME but I am using it as a simple example.
I used it a while back for a client. They were using a version of Sybase IQ which was current at the time. It did not have getdate() or equivalent, so there was no way to obtain the current system date and make objects based off of that. So we used @script() to obtain the current date from the local workstation that was running the report and used that for date calculations instead.
That was also in version 4.
In looking at your code, the first thing that comes to mind is you’ve written a procedure rather than a function, therefore there is no return value. Try defining your sub as a function with a return value instead of a procedure and see what happens.
Ha, I actually managed to find the script that we used. And it doesn’t require a function, but the value needed to be set in an Application variable. The code:
Sub main
' This script returns the current client PC's system date
Application.Variables.Item("DTest").Value = CVar(Date)
End Sub
The variable “DTest” was our “date test” and was how the value got passed. Try that syntax and see if it works.