How to Dim Array

S

Scott

I get an "expected array" error when running my code. This code runs fine in
ASP, but I don't know how to dim an array in Access. The code splits a date
time string called dtTargetDateStamp into a date and time variable.

Can someone explain how to properly Dim the dateArray1 variable below?


CODE ***********************
Dim FSO As New FileSystemObject
Dim dtTargetDateStamp As String

dtTargetDateStamp = Now()

Dim dateArray1 As String
Dim sTime As String, sDate As String

dateArray1 = Split(CStr(dtTargetDateStamp), ":")
sTime = Int(Right(dateArray1(0), 2)) & ":" & dateArray1(1) &
":" & dateArray1(2)
 
G

Guest

There's a topic in Access help called Declaring arrays. Basically, it looks
like this:
Dim dateArray1() As String 'Uninitialized array, would require a Redim
statement
or
Dim dateArray(1) As String ' Declared with two elements

Barry
 
G

Guest

You do not use an array for the destination of the Split function. The data
type of the destination of the Split function needs to be a Variant, not a
string.

I can't tell what you are trying to do with the date. If you can give me a
description of what you are trying to accomplish, there are date datatype
function that will probably work better for you. I would be happy to have a
look.
 
D

Dirk Goldgar

Klatuu said:
You do not use an array for the destination of the Split function.
The data type of the destination of the Split function needs to be a
Variant, not a string.

That depends on what version of Access (or VBA) you are using, IIRC. I
*think* in Access 2000 you had to use a variant, but in Access 2002 you
can write:

Dim MyArray() As String

MyArray = Split("a,b,c", ",")

That's the way I usually do it.
 
J

J. Goddard

Using an string array in A2000 works fine. If unsubscripted in the Dim
statement, it does have to be a variant.

John
 
D

Dirk Goldgar

J. Goddard said:
Using an string array in A2000 works fine. If unsubscripted in the
Dim statement, it does have to be a variant.

Thanks for setting me straight. I'm not sure what I was thinking of,
then, unless it was VBScript.
 

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