toggling visibility of labels through code

D

DawnTreader

Hello All

i need a little help trying to get this to work

i have 3 sets of lables for 3 different languages for my fields. i am trying
to use a variable stored in a combo box on a floating always open form to
determine which language label should show. what is wrong with this code?

Private Sub frmLanguage()
Dim ctl As Control
Dim frmUserLanguage As String
Dim lblLanguage As String

frmUserLanguage = Forms!frmMainMenu.Form!cboEmployee.Column(18)

MsgBox frmUserLanguage

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
lblLanguage = ctl.Tag
MsgBox lblLanguage
Select Case lblLanguage
Case lblLanguage = frmUserLanguage
ctl.Visible = True
Case lblLanguage = "Always"
ctl.Visible = True
Case Else
ctl.Visible = False
End Select
End If
Next
End Sub
 
D

DawnTreader

doh!

figured it out, thanks any ways.

Private Sub frmLanguage()
Dim ctl As Control
Dim frmUserLanguage As String
Dim lblLanguage As String

frmUserLanguage = Forms!frmMainMenu!cboEmployee.Column(18)

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
lblLanguage = ctl.Tag
Select Case lblLanguage
Case frmUserLanguage
ctl.Visible = True
Case "Always"
ctl.Visible = True
Case Else
ctl.Visible = False
End Select
End If
Next
End Sub
 
M

Marshall Barton

DawnTreader said:
i have 3 sets of lables for 3 different languages for my fields. i am trying
to use a variable stored in a combo box on a floating always open form to
determine which language label should show. what is wrong with this code?

Private Sub frmLanguage()
Dim ctl As Control
Dim frmUserLanguage As String
Dim lblLanguage As String

frmUserLanguage = Forms!frmMainMenu.Form!cboEmployee.Column(18)

MsgBox frmUserLanguage

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
lblLanguage = ctl.Tag
MsgBox lblLanguage
Select Case lblLanguage
Case lblLanguage = frmUserLanguage
ctl.Visible = True
Case lblLanguage = "Always"
ctl.Visible = True
Case Else
ctl.Visible = False
End Select
End If
Next
End Sub


Your Case statments us invalis syntax. Try something more
like:

Select Case lblLanguage
Case frmUserLanguage, "Always"
ctl.Visible = True
Case Else
ctl.Visible = False
End Select

Or, more concisely:

ctl.Visible = lblLanguage = frmUserLanguage _
Or lblLanguage = "Always"
 
D

Douglas J. Steele

Yes, that's what Marsh is saying

For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
lblLanguage = ctl.Tag
MsgBox lblLanguage

ctl.Visible = ((lblLanguage = frmUserLanguage) _
Or (lblLanguage = "Always"))
End If
Next ctl
 
M

Marshall Barton

DawnTreader said:
are you saying i could do away with the select statement altogether?


Sure. There are only two possible outcomes, True or False.
So, the ones that should make the control visible just have
to be listed in the expression. Kind of like my suggested
Case statement using Or instead of comma. Think about it,
it's really not complicated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top