Dynamic dimming

B

Biggles

I wasn't even sure what to search this on, but can I do this?:

v_ctr = 1
Do Until v_ctr > 3
dim (ssql & v_ctr) as String
Loop

instead of:

dim ssql1 as string
dim ssql2 as string
dim ssql3 as string
 
D

Dirk Goldgar

In
Biggles said:
I wasn't even sure what to search this on, but can I do this?:

v_ctr = 1
Do Until v_ctr > 3
dim (ssql & v_ctr) as String
Loop

instead of:

dim ssql1 as string
dim ssql2 as string
dim ssql3 as string

No. But you can do this:

Dim ssql(1 To 3) As String

.... and then refer to the individual elements of the array using
subscripts.
 
B

Biggles

Thanks Dirk, I will use that method.

I posted the previous before I ran to a meeting, so now I have a follow up
question. Should I use different SSQL statements if I want to have multiple
recordsets open, i.e.

SSQL1 = "Select ..."
RS1.openrecordset ssql1 'this needs to stay open
ssql2 = "Select ... "
RS2.openrecordset ssql2 'this needs to stay open as well

or is this method below courting danger:

SSQL1 = "Select ..."
RS1.openrecordset ssql1 'this needs to stay open
ssql1 = "Select ... "
RS2.openrecordset ssql1

Thanks.
 
B

Biggles

Ok, it turns out I don't know how to reference this, do I use:

dim ssql(1 to 3) as string

ssql1 =
ssql(1) =
?
 
B

Biggles

I answered this myself, it is ssql(1) - it helps if you use the same name in
the dim statement as when you try to reference it.
 
G

George Nicholson

reusing the ssql variable is fine.

ssql's value *at the time a recordset is opened* is all that matters. the
recordset doesn't maintain any kind of reference/pointer back to the
variable.

HTH,
 
Top