Paasing an array in OpenArgs

R

RipperT

Access 2000. I have a simple form with two unbound text boxes for the user
to enter a date range and a button to open a report resticted by the dates.
I would like the two dates passed on to the report to show in labels when it
opens. I thought a good way to do this would be to create an array with the
two date values and pass the array in the openargs argument. (This may not
be the best way, but this is my first venture into arrays). Access help says
I can refer to the array as a whole (but doesn't explain how) when I want to
refer to all the values it holds, or I can refer to its individual elements.
Since there is only one openargs argument and it has to be a string, is
there a way to pass the single array variable to the report's open event and
then extract the two dates for use in the report? I've created the array
simply enough, but Access won't let me pass it using openargs.

Dim stDocName As String
Dim varDate(1) As Variant
varDate(0) = Forms!frmMain.txtStartDate
varDate(1) = Forms!frmMain.txtEndDate
stDocName = "rptMonthlyStats"
DoCmd.OpenReport stDocName, acViewPreview, , , , varDate

This generates the error: An expression you entered is the wrong data type
for one of the arguments
Access help says that if I declare the array as type variant, I can place a
whole array in a variant resulting in a single variant variable containing
the whole array. Can I not then pass this single variant in the openargs
argument?

Many thanks,

Rip
 
A

Allen Browne

OpenArgs is a single value.

You could pass a delimited string, and then use the Split() function to
parse it into an array.
 
B

Brendan Reynolds

Although the OpenArgs property is a variant, the Access 2003 help file
indicates it must contain a string expression.

<quote>
Determines the string expression specified by the OpenArgs argument of the
OpenForm method that opened a form. Read/write Variant.
</quote>

You'll probably need to pass a delimited string, e.g.
"somedate;someotherdate", where ";" is the delimiter. You can use the Split
function to convert the delimited string into an array in the Open event of
the report. But, are you sure you're using Access 2000? Because my
understanding is that in Access 2000 reports (unlike forms) don't have an
OpenArgs property. My understanding it that that property was added to
reports in a later version.
 
D

Dirk Goldgar

Allen Browne said:
OpenArgs is a single value.

You could pass a delimited string, and then use the Split() function to
parse it into an array.


And Ripper may want to use the Join() function to create the delimited
string from the array in the first place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top