@Script example?

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.

Thank You


mdoering (BOB member since 2003-11-20)

Looking forward to seeing this work. In the 9 years I’ve used BO, I’ve never seen anyone actually use @script (other than in the training material).


Steve Krandel :us: (BOB member since 2002-06-25)

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. :slight_smile:

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.


Dave Rathbun :us: (BOB member since 2002-06-06)

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.


Dave Rathbun :us: (BOB member since 2002-06-06)