How Do I create an Object reference from a string? 
Author Message
 How Do I create an Object reference from a string?

Adam,

Easy as pie, I just learned this one recently..  Here is an example:

For i = 1 to 10
    Me("String Value"& i).Visilbe = True
Next i


Quote:
> Dear All,

> I have a form which has as it's base a query which splits a year up into 4
> Quarters & 52 weeks (1-13 X 4)

> Each total quantity for each week is put into a separate text box (A1 ->
> A52)

> At the moment I have a horrifically repeative bit of code (see below)

> What I would like to be able to do is to create the "me.A1", me.A2 etc as
> simply a var value "meA" & then add the 1,2,3 etc onto it as required.

> So How can I do this?

> I have thought of creating a string eg.
> Dim ObjRef As String
> ObjRef = "me.A"

> & then appending a value (i.e the number)

> TIA

> Adam

> Set DB = DBEngine.Workspaces(0).Databases(0)
> Set Tbl = DB.OpenRecordset("Ordgrid_dist_q", DB_OPEN_DYNASET)   ' Create
> table.
> Tbl.MoveFirst
> Do While Not Tbl.EOF
> If Tbl![Q] = 1 Then
> Me.Q1 = (Tbl![Q])
> Me.A1 = (Tbl![WK1])
> Me.A2 = (Tbl![WK2])
> Me.A3 = (Tbl![WK3])
> Me.A4 = (Tbl![WK4])
> Me.A5 = (Tbl![WK5])
> Me.A6 = (Tbl![WK6])
> Me.A7 = (Tbl![WK7])
> Me.A8 = (Tbl![WK8])
> Me.A9 = (Tbl![WK9])
> Me.A10 = (Tbl![WK10])
> Me.A11 = (Tbl![WK11])
> Me.A12 = (Tbl![WK12])
> Me.A13 = (Tbl![WK13])
> End If
> If Tbl![Q] = 2 Then
> Me.Q2 = (Tbl![Q])
> Me.A14 = (Tbl![WK1])
> Me.A15 = (Tbl![WK2])
> Me.A16 = (Tbl![WK3])
> Me.A17 = (Tbl![WK4])
> Me.A18 = (Tbl![WK5])
> Me.A19 = (Tbl![WK6])
> Me.A20 = (Tbl![WK7])
> Me.A21 = (Tbl![WK8])
> Me.A22 = (Tbl![WK9])
> Me.A23 = (Tbl![WK10])
> Me.A24 = (Tbl![WK11])
> Me.A25 = (Tbl![WK12])
> Me.A26 = (Tbl![WK13])
> End If
> If Tbl![Q] = 3 Then
> Me.Q3 = (Tbl![Q])
> Me.A27 = (Tbl![WK1])
> Me.A28 = (Tbl![WK2])
> Me.A29 = (Tbl![WK3])
> Me.A30 = (Tbl![WK4])
> Me.A31 = (Tbl![WK5])
> Me.A32 = (Tbl![WK6])
> Me.A33 = (Tbl![WK7])
> Me.A34 = (Tbl![WK8])
> Me.A35 = (Tbl![WK9])
> Me.A36 = (Tbl![WK10])
> Me.A37 = (Tbl![WK11])
> Me.A38 = (Tbl![WK12])
> Me.A39 = (Tbl![WK13])
> End If
> If Tbl![Q] = 4 Then
> Me.Q4 = (Tbl![Q])
> Me.A40 = (Tbl![WK1])
> Me.A41 = (Tbl![WK2])
> Me.A42 = (Tbl![WK3])
> Me.A43 = (Tbl![WK4])
> Me.A44 = (Tbl![WK5])
> Me.A45 = (Tbl![WK6])
> Me.A46 = (Tbl![WK7])
> Me.A47 = (Tbl![WK8])
> Me.A48 = (Tbl![WK9])
> Me.A49 = (Tbl![WK10])
> Me.A50 = (Tbl![WK11])
> Me.A51 = (Tbl![WK12])
> Me.A52 = (Tbl![WK13])
> End If

> Tbl.MoveNext
> Loop



Sat, 09 Nov 2002 03:00:00 GMT  
 How Do I create an Object reference from a string?
You can use Me("A" & i) where i is a variable.

 -- Andy

Quote:

>Dear All,

>I have a form which has as it's base a query which splits a year up into 4
>Quarters & 52 weeks (1-13 X 4)

>Each total quantity for each week is put into a separate text box (A1 ->
>A52)

>At the moment I have a horrifically repeative bit of code (see below)

>What I would like to be able to do is to create the "me.A1", me.A2 etc as
>simply a var value "meA" & then add the 1,2,3 etc onto it as required.

>So How can I do this?

>I have thought of creating a string eg.
>Dim ObjRef As String
>ObjRef = "me.A"

>& then appending a value (i.e the number)

>TIA

>Adam

>Set DB = DBEngine.Workspaces(0).Databases(0)
>Set Tbl = DB.OpenRecordset("Ordgrid_dist_q", DB_OPEN_DYNASET)   ' Create
>table.
>Tbl.MoveFirst
>Do While Not Tbl.EOF
>If Tbl![Q] = 1 Then
>Me.Q1 = (Tbl![Q])
>Me.A1 = (Tbl![WK1])
>Me.A2 = (Tbl![WK2])
>Me.A3 = (Tbl![WK3])
>Me.A4 = (Tbl![WK4])
>Me.A5 = (Tbl![WK5])
>Me.A6 = (Tbl![WK6])
>Me.A7 = (Tbl![WK7])
>Me.A8 = (Tbl![WK8])
>Me.A9 = (Tbl![WK9])
>Me.A10 = (Tbl![WK10])
>Me.A11 = (Tbl![WK11])
>Me.A12 = (Tbl![WK12])
>Me.A13 = (Tbl![WK13])
>End If
>If Tbl![Q] = 2 Then
>Me.Q2 = (Tbl![Q])
>Me.A14 = (Tbl![WK1])
>Me.A15 = (Tbl![WK2])
>Me.A16 = (Tbl![WK3])
>Me.A17 = (Tbl![WK4])
>Me.A18 = (Tbl![WK5])
>Me.A19 = (Tbl![WK6])
>Me.A20 = (Tbl![WK7])
>Me.A21 = (Tbl![WK8])
>Me.A22 = (Tbl![WK9])
>Me.A23 = (Tbl![WK10])
>Me.A24 = (Tbl![WK11])
>Me.A25 = (Tbl![WK12])
>Me.A26 = (Tbl![WK13])
>End If
>If Tbl![Q] = 3 Then
>Me.Q3 = (Tbl![Q])
>Me.A27 = (Tbl![WK1])
>Me.A28 = (Tbl![WK2])
>Me.A29 = (Tbl![WK3])
>Me.A30 = (Tbl![WK4])
>Me.A31 = (Tbl![WK5])
>Me.A32 = (Tbl![WK6])
>Me.A33 = (Tbl![WK7])
>Me.A34 = (Tbl![WK8])
>Me.A35 = (Tbl![WK9])
>Me.A36 = (Tbl![WK10])
>Me.A37 = (Tbl![WK11])
>Me.A38 = (Tbl![WK12])
>Me.A39 = (Tbl![WK13])
>End If
>If Tbl![Q] = 4 Then
>Me.Q4 = (Tbl![Q])
>Me.A40 = (Tbl![WK1])
>Me.A41 = (Tbl![WK2])
>Me.A42 = (Tbl![WK3])
>Me.A43 = (Tbl![WK4])
>Me.A44 = (Tbl![WK5])
>Me.A45 = (Tbl![WK6])
>Me.A46 = (Tbl![WK7])
>Me.A47 = (Tbl![WK8])
>Me.A48 = (Tbl![WK9])
>Me.A49 = (Tbl![WK10])
>Me.A50 = (Tbl![WK11])
>Me.A51 = (Tbl![WK12])
>Me.A52 = (Tbl![WK13])
>End If

>Tbl.MoveNext
>Loop



Sat, 09 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ActiveX component can't create object or return reference to this object (Error 429)

2. Activex component can't create object or return reference to this object (Error

3. Passing an object reference by reference where the object has a default property

4. HELP : Using a string to create a reference to Form Controls

5. Reference to an object from a String value

6. referencing object (form, report) using string variable

7. Obtain a reference to a form object through a string

8. Getting a reference to a loaded object from a string variable

9. I want to access an object by using a string reference

10. reference a control or object via a string

11. referencing objects with string variables?

12. VBA - Creating a reference to an Existing object

 

 
Powered by phpBB® Forum Software