Arrays (1 Viewer)

pekajo

Registered User.
Local time
Tomorrow, 06:04
Joined
Jul 25, 2011
Messages
133
Hi,
Hope you can help.
I have two arrays and want to use to edit a table. For example this is what it looks like normally:
rs1.Edit
rs1![Ready Date] = "[R Date]"
rs1.Update
rs1.MoveNext

This is what I am after:
rs1.Edit
myarray1(1) = myarray2(1)
rs1.Update
rs1.MoveNext

myarray1(1) = "rs1![Ready Date]"
myarray2(1) = "[R Date]"

Is this possible?
Thanks for any help
Peter
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 28, 2001
Messages
27,231
You can do something similar but not identical to what you specified.

If MyArray1(1) is "Ready Date" (no brackets, no explicit recordset reference but it IS a field in RS1) and MyArray2(1) is "[R Date] - AND [R Date] IS a control on the current form

Code:
RS1.Fields( MyArray1(1) ) = Me.Controls( MyArray2(1) )

This works because in both cases, the default property for the items I showed you is .Value, so you CAN get away with this much indirect referencing. More than this? I'm EXTREMELY skeptical of going any farther than what I showed you above.

You are trying to substitute instruction-line elements to VBA to indirectly reference something not shown on that line. I don't think you can do that because I don't know of a mechanism that allows that sequence of indirect instruction referencing. I only know of one operating system that allows that kind of indirection and Windows ain't it. Besides which, what you requested is not a true command-line. VBA is pseudo-compiled - but the pseudo-code is then emulated. Your deferred reference is inconsistent with a compiler, which is what VBA is. You might be able to do this in SOME languages, but VBA isn't one of them.

I also have to advise that even this much indirection might be a bit touchy because you have s;paces in your field and control names. While legal, they can get in the way when dealing with syntax involving substitution or collection-indexing (the latter of which is what I showed as a solution closest to your request.)
 

Ranman256

Well-known member
Local time
Today, 16:04
Joined
Apr 9, 2015
Messages
4,337
really no need for arrays anymore in a recordset world.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:04
Joined
Feb 28, 2001
Messages
27,231
@Ranman256 - the problem is less about arrays and recordsets and more about indirect references in an instruction - a form of late binding of variables.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:04
Joined
Feb 19, 2002
Messages
43,371
What you are envisioning isn't actually going to save coding or time. It simply abstracts the process so that no one will be able to understand it. You still need 2 times x lines of code to set all the array values so a loop to copy is actually three times as much work as the list of direct reverences because now you need a loop that executes x times to copy a to b.

So in stead of
a = a1
b = b1
you have to load a-x into the array and then load a1-x1 into the second array and then the loop to do what you should have done instead of copying a to a1 in the first place.
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:04
Joined
Jan 23, 2006
Messages
15,385
Peter,
You have gotten advice for your question, but I'd like to see a plain English description about the arrays and their source(s) and how they fit into the issue you are trying to resolve. Call me nosy, but I'm just curious.

There is nothing inherently wrong with arrays. They are a structure/tool. You'll find there are many ways to resolve issues - nice to have a few tools in the arsenal.
 

Users who are viewing this thread

Top Bottom