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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|