Run time error 2450 when populating an array, help please.

Maybe you can post some images of your form and some explanation of the tables. I just can imagine a much, much simpler bound approach or a much simpler unbound approach.
This looks like a painful amount of negative work.
 
@ OP,
As you are referencing controls on a SUBFORM, you will need to use different syntax.

Forms.ParentForm.SubForm.Form.ControlName

You also do not need to create the array of objects, you can instead loop through your controls and fill your array of variables instead. No need for double work.
 
Mark_, regarding direct vs indirect filling of arrays - True. I wonder at how many piles of data structures get tossed into the (literal or figurative) heap by this process. I could see the application getting really large in terms of virtual memory usage if this happens several times in one launch of the app.
 
@ Doc,
I've seen these kinds of issues before. Unless the OP is doing something with his array (such as allowing some kind of "Undo") I'm not getting a purpose for it other than to have it. Similarly I'd not have multiple subforms with the same control names. I'd have put them all on the same form, just different tabs.

I can get what he is trying for. Standard sets of items sold together and a way to easily load a "Set". There are other ways to get the same results, especially if he's trying to allow some to be omitted from a given sale.
 
Guys, I think I see the problem now. It seems it was a syntax error all along. I forgot to mention that I'm working on a form that has 4 sub forms in it, using tabs. So, now I just need to figure out how to write it properly.

I've decided to use a dictionary, here is what i've written so far for my tests

Code:
Set Chk_Dictionary = New Dictionary
Set Cbo_Dictionary = New Dictionary
Set TxtU_Dictionary = New Dictionary
Set TxtV_Dictionary = New Dictionary
        
    For i = 1 To 10
        Chk_Dictionary.Add "Chk" & CStr(i), Forms("subfrm_Cotizacion_1_10").Controls("Chk_p_" & CStr(i))
        Cbo_Dictionary.Add "Cbo" & CStr(i), Forms("subfrm_Cotizacion_1_10").Controls("cbo_cod_" & CStr(i))
        TxtU_Dictionary.Add "TxtU" & CStr(i), Forms("subfrm_Cotizacion_1_10").Controls("txt_uni_" & CStr(i))
        TxtV_Dictionary.Add "TxtV" & CStr(i), Forms("subfrm_Cotizacion_1_10").Controls("txt_PrecioUnitario_" & CStr(i))
    Next i

How should I write the reference for an object that is inside of a sub form?
 
I forgot to mention that I'm working on a form that has 4 sub forms in it, using tabs. So, now I just need to figure out how to write it properly.

...

How should I write the reference for an object that is inside of a sub form?

Please look at post 22.

Forms.ParentForm.SubForm.Form.ControlName

What is the name of your parent form? Going back I can see the SubForm names.
 
Please look at post 22.

Forms.ParentForm.SubForm.Form.ControlName

What is the name of your parent form? Going back I can see the SubForm names.

The name of my parent form is: frm_Cotizacion

The children are contained inside of a tab control called: tab_Cotizacion with five pages called: pag_1, pag_2 ... pag_5


The children are called (these are also the name of the subform controls):

subfrm_Cotizacion_1_10

subfrm_Cotizacion_11_20

subfrm_Cotizacion_21_30

subfrm_Cotizacion_31_40

subfrm_Cotizacion_41_50
 
Last edited:
So now you have a complicated solution to a non-problem. This is fine if it is some academic curiosity, but no one would do it this way. Still recommend you explain what you are trying to do. 100% guarantee you we can provide a far easier, far more flexible, and far more reusable solution. In my opinion this is a Rude Goldberg machine (which are hilarious).
https://en.wikipedia.org/wiki/Rube_Goldberg_machine
 

Users who are viewing this thread

Back
Top Bottom