Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

visible controls

Status
Not open for further replies.

mypeljo

Technical User
Apr 16, 2010
12
BG
Visible controls

In my form the code for making controls visible and invisible does not work. My code is the following:
Private Sub Form_Current()
If Me![supplierid] = 1 Then
Me.RaufGrade.Visible = False
Me.RaufCode.Visible = False
Me.AralGrade.Visible = True
Me.AralCode.Visible = True
ElseIf Me![supplierid] = 2 Then
Me.AralGrade.Visible = False
Me.AralCode.Visible = False
Me.RaufGrade.Visible = True
Me.RaufCode.Visible = True
End If
End Sub

Why is it so? Is it because the form is continous? How can I make it work?
 
the form is continous
So, I'd look at conditional formatting.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
By the way, for ease of debugging, I'd highly suggest you add indentation and spacing into your code. So, it would look something like this:
Code:
Private Sub Form_Current()
     If Me![supplierid] = 1 Then
          Me.RaufGrade.Visible = False
          Me.RaufCode.Visible = False
          Me.AralGrade.Visible = True
          Me.AralCode.Visible = True
     ElseIf Me![supplierid] = 2 Then
          Me.AralGrade.Visible = False
          Me.AralCode.Visible = False
          Me.RaufGrade.Visible = True
          Me.RaufCode.Visible = True
     End If
End Sub

Just as a general rule. That way, it makes it a WHOLE LOT easier to browse through your code to see what is going on, and when it is happening.
 
Also note that you cannot control visibility/invisibility of a control thru Conditional Formatting. The best you can do is to set the forecolor/backcolor the same as the backcolor of the form section to simulate this.

In Design View you'll also have to

Select the field
Goto Properties - Format
Set Special Effect to Flat

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
How are ya mypeljo . . .

You can also disable a control thru [blue]Conditional Formatting[/blue], giving it [blue]that disabled look[/blue] ...

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 

Not the answer to your question, just the suggestion for the code:
Code:
Private Sub Form_Current()
     Me.RaufGrade.Visible = False
     Me.RaufCode.Visible = False
     Me.AralGrade.Visible = False
     Me.AralCode.Visible = False

     If Me![supplierid] = 1 Then
          Me.AralGrade.Visible = True
          Me.AralCode.Visible = True
     ElseIf Me![supplierid] = 2 Then
          Me.RaufGrade.Visible = True
          Me.RaufCode.Visible = True
     End If
End Sub
Imagine if you add another 4 controls and another 2 supplierid to the mix, this approach would make a lot simpler to keep all of these organized (IMHO)

Have fun.

---- Andy
 
Andy, the OP talk about a continuous form ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top