A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Form References



 
 
Thread Tools Display Modes
  #1  
Old March 1st, 2010, 12:02 AM posted to microsoft.public.access
PeterM
external usenet poster
 
Posts: 208
Default Form References

I have a form (switchboard) and on SwitchBoard is a subform control
(subform!).
There are 10 fields on SwitchBoard entitled Program1 thru Program10. From
within subform1 I issued:

Dim i As Integer
For i = 1 To 10
Me("forms!switchboard!Program" & i).ForeColor =
DLookup("Boxclickedbordercolor", "SystemTable")
Next i

that code doesn't work. So I changed it to the literal below just for
testing and this code works.

Forms!switchboard!Program1.ForeColor = DLookup("Boxclickedbordercolor",
"SystemTable")


What is wrong for the first version?

Thanks for your help!
  #2  
Old March 1st, 2010, 02:32 AM posted to microsoft.public.access
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Form References

"PeterM" wrote in message
...
I have a form (switchboard) and on SwitchBoard is a subform control
(subform!).
There are 10 fields on SwitchBoard entitled Program1 thru Program10. From
within subform1 I issued:

Dim i As Integer
For i = 1 To 10
Me("forms!switchboard!Program" & i).ForeColor =
DLookup("Boxclickedbordercolor", "SystemTable")
Next i

that code doesn't work. So I changed it to the literal below just for
testing and this code works.

Forms!switchboard!Program1.ForeColor = DLookup("Boxclickedbordercolor",
"SystemTable")


What is wrong for the first version?



"Me" refers to the module that is running the code; in this case, the
subform. Your expression:

Me("forms!switchboard!Program" & i)


.... implies that "forms!switchboard!Program1" (and its friends) are controls
on the subform, but they aren't. You should drop the "Me", and write your
loop like this:

Dim lngColor As Long
Dim i As Integer

lngColor = DLookup("Boxclickedbordercolor", "SystemTable")

For i = 1 To 10
Forms!switchboard.Controls("Program" & i).ForeColor = lngColor
Next i

That would be the general case. Since you know that this code is running on
a subform of the form "switchboard", you could simplify the form reference
to:

Me.Parent.Controls("Program" & i).ForeColor = lngColor



--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

  #3  
Old March 1st, 2010, 02:54 AM posted to microsoft.public.access
PeterM
external usenet poster
 
Posts: 208
Default Form References

Thanks Dirk... worked like a charm!

"Dirk Goldgar" wrote:

"PeterM" wrote in message
...
I have a form (switchboard) and on SwitchBoard is a subform control
(subform!).
There are 10 fields on SwitchBoard entitled Program1 thru Program10. From
within subform1 I issued:

Dim i As Integer
For i = 1 To 10
Me("forms!switchboard!Program" & i).ForeColor =
DLookup("Boxclickedbordercolor", "SystemTable")
Next i

that code doesn't work. So I changed it to the literal below just for
testing and this code works.

Forms!switchboard!Program1.ForeColor = DLookup("Boxclickedbordercolor",
"SystemTable")


What is wrong for the first version?



"Me" refers to the module that is running the code; in this case, the
subform. Your expression:

Me("forms!switchboard!Program" & i)


... implies that "forms!switchboard!Program1" (and its friends) are controls
on the subform, but they aren't. You should drop the "Me", and write your
loop like this:

Dim lngColor As Long
Dim i As Integer

lngColor = DLookup("Boxclickedbordercolor", "SystemTable")

For i = 1 To 10
Forms!switchboard.Controls("Program" & i).ForeColor = lngColor
Next i

That would be the general case. Since you know that this code is running on
a subform of the form "switchboard", you could simplify the form reference
to:

Me.Parent.Controls("Program" & i).ForeColor = lngColor



--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.