Visibility same as previous record

8

8l2255

Hi,

I have a form with some combo boxes and then some fields. If in the combo
box a SIM card is selected I want the Phone number field to show, but only
for SIM card.

The problem I have is that when I go to next record or previous record the
visibility remains the same from the last cbo update, not as it should be in
the current record.

Private Sub CatIDCBO_Afterupdate()
If CatIDCBO = 2 Then
IMEI.Visible = False
SIMCardNo.Visible = True
SIMPhNo.Visible = True
PlanID.Visible = True
PIN.Visible = True
PUK.Visible = True
ElseIf CatIDCBO = 1 Then
IMEI.Visible = True
SIMCardNo.Visible = False
SIMPhNo.Visible = False
PlanID.Visible = False
PIN.Visible = False
PUK.Visible = False
ElseIf CatIDCBO = 3 Then
IMEI.Visible = True
SIMCardNo.Visible = False
SIMPhNo.Visible = False
PlanID.Visible = False
PIN.Visible = False
PUK.Visible = False
ElseIf Not CatIDCBO And Not 2 And Not 1 Then
IMEI.Visible = False
SIMCardNo.Visible = False
SIMPhNo.Visible = False
PlanID.Visible = False
PIN.Visible = False
PUK.Visible = False
End If
End Sub

I have only just started working with VBA so if there are problems please
let me know.

Thanks!!
 
8

8l2255

Right I answered my own question after much searching.

All i had to do was add the code to on current!!!!
 
J

John Smith

You also have a problem with your last clause:

ElseIf Not CatIDCBO And Not 2 And Not 1 Then

It's a valid statement but will not do what I suspect that you want. If you
write the code this way I think you mean:

ElseIf CatIDCBO <> 2 And CatIDCBO <> 1 Then

but if you set them all invisible and then used a Case statement instead you
might find it easier to see what was happening:

IMEI.Visible = False
SIMCardNo.Visible = False
SIMPhNo.Visible = False
PlanID.Visible = False
PIN.Visible = False
PUK.Visible = False

Select Case CatIDCBO
Case 1
IMEI.Visible = True
Case 2
SIMCardNo.Visible = True
SIMPhNo.Visible = True
PlanID.Visible = True
PIN.Visible = True
PUK.Visible = True
Case 3
IMEI.Visible = True
End Select

You will also find that indenting your structures makes spotting errors such as
a missing 'End' much easier to do.

HTH
John
##################################
Don't Print - Save trees
 

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