Select case statement and controls

iampaul

Registered User.
Local time
Today, 12:29
Joined
Apr 19, 2005
Messages
14
Is there a neater / simpler way to write the following, bearing ni mind that fro case 1 the control is called ....PF1 and for case 2 .....PF2?

Select Case intPfNumber
Case 1
Set ctlList = Forms.frmMain.lstPF1
Set ctlTree = Forms.frmMain.CtlTreePF1
Set ctlCombo = Forms.frmMain.cboPF1
Set lblBmName = Forms.frmMain.lblBmNamePF1
Set lblColHeads = Forms.frmMain.lblColHeadsPF1
Case 2
Set ctlList = Forms.frmMain.lstPF2
Set ctlTree = Forms.frmMain.CtlTreePF2
Set ctlCombo = Forms.frmMain.cboPF2
Set lblBmName = Forms.frmMain.lblBmNamePF2
Set lblColHeads = Forms.frmMain.lblColHeadsPF2
End Select
 
It is, but I may move it to a class module. That is why it currently reads:
forms!frmMain. ... rather than me. ...

I just wondered, seeing as the only difference in control names is the 1 or 2 at the end, if there was a simpler way to write it. Seemed I was decalring alot of control variables and writing a long select case statment to do something really simple.
 
You could do some more efficent code if the list of stuff you were changing was longer, but I suspect what you have is about as good as you'll need.

Here is some addition reading - You may be interested the (" ") notation as you could build a string for the control names dynamically...

Link
 
Code:
Set ctlList = Forms("frmMain")("lstPF" & intPfNumber)
Set ctlTree = Forms("frmMain")("CtlTreePF" & intPfNumber)
Set ctlCombo = Forms("frmMain")("cboPF" & intPfNumber)
Set lblBmName = Forms("frmMain")("lblBmNamePF" & intPfNumber)
Set lblColHeads = Forms("frmMain")("lblColHeadsPF" & intPfNumber)
 
Mile-O will correct me, but I think you can get rid of the Select case and put:

With Forms!frmMain

Set ctlList = ("lstPF" & intPfNumber)
Set ctlTree = ("CtlTreePF" & intPfNumber)
Set ctlCombo = ("cboPF" & intPfNumber)
Set lblBmName = ("lblBmNamePF" & intPfNumber)
Set lblColHeads = ("lblColHeadsPF" & intPfNumber)

End With

I have used
Me("cmdSweep" & IntNum).Visible = True
and it works OK

Not sure if the code is abosolutly correct but you get the idea
HTH

Dave
 

Users who are viewing this thread

Back
Top Bottom