By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Form Addressing from variable

P: n/a
I want to do this from a for/next loop:

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

The compiler doesn't understand I want to use the variable 'Temp'
instead of a form named "Temp".

How do I get around this?

------

Current code is:

Private Sub cmdColorize_Click()
Dim aryForm2(0) As String
aryForm2(0) = "frmqunioncomp"

Dim frm2end As Integer
Dim count As Integer
Dim temp As String

For count = 0 To UBound(aryForm2)

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

Next
End Sub
------

Dec 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try:
Forms(aryForm2(count)).BackColor = ...

Item is the default collection for forms, so it's an abbreviation of this
kind of construct:
Forms.Item("Form1")

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ch************@yahoo.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
>I want to do this from a for/next loop:

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

The compiler doesn't understand I want to use the variable 'Temp'
instead of a form named "Temp".

How do I get around this?

------

Current code is:

Private Sub cmdColorize_Click()
Dim aryForm2(0) As String
aryForm2(0) = "frmqunioncomp"

Dim frm2end As Integer
Dim count As Integer
Dim temp As String

For count = 0 To UBound(aryForm2)

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

Next
End Sub
------

Dec 14 '06 #2

P: n/a
call the string variable something else?

some folks would hang you for not calling them StrTemp and FrmTemp in the
first place

<ch************@yahoo.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
>I want to do this from a for/next loop:

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

The compiler doesn't understand I want to use the variable 'Temp'
instead of a form named "Temp".

How do I get around this?

------

Current code is:

Private Sub cmdColorize_Click()
Dim aryForm2(0) As String
aryForm2(0) = "frmqunioncomp"

Dim frm2end As Integer
Dim count As Integer
Dim temp As String

For count = 0 To UBound(aryForm2)

DoCmd.OpenForm aryForm2(count), acDesign, , , , acWindowNormal
Temp = aryForm2(count)
Forms!Temp.Section(1).BackColor = Forms!zfrmcolor!color2

Next
End Sub
------


Dec 14 '06 #3

P: n/a

Allen Brown wrote:
Try:
Forms(aryForm2(count)).BackColor = ...
Item is the default collection for forms, so it's an abbreviation of this
kind of construct:
Forms.Item("Form1")
OMG - it worked!

Thanks Allen! You just saved me a ton of time and code!
- Christian

Dec 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.