If Then Else Trouble

R

RobUCSD

Could somebody take a look at the code below. I can't seem to get it to work.
I get a msg saying "This method or procedure not supported in Private Sub
lstVisit_GotFocus()" thanks, rob

*********************************************************
Private Sub lstVisit_GotFocus()
On Error GoTo lstVisit_GotFocus_Error

Me.Form.AllowEdits = True
Me.Refresh



If Me.VisitType = "Ablation" Then

Me.pgAblations.Visible = True
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = False
Me.pgTilts.Visible = False
Me.pgTelephone = False

ElseIf Me.VisitType = "Device" Then

Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = True
Me.pgTilts.Visible = False
Me.pgTelephone = False


ElseIf Me.VisitType = "Clinic" Then


Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = True
Me.pgDevices.Visible = False
Me.pgTilts.Visible = False
Me.pgTelephone = False


ElseIf Me.VisitType = "Cardioversion" Then

Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = True
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = False
Me.pgTilts.Visible = False
Me.pgTelephone = False

ElseIf Me.VisitType = "Telephone" Then

Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = False
Me.pgTilts.Visible = False
Me.pgTelephone = True


ElseIf Me.VisitType = "Tilt Table" Then

Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = False
Me.pgTilts.Visible = True
Me.pgTelephone = False

End If




On Error GoTo 0
Exit Sub

lstVisit_GotFocus_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
lstVisit_GotFocus of VBA Document Form_frmVisitNewEdit"

End Sub
 
S

SteveS

You are missing the .Visible in each of these lines:
Me.pgTelephone = False

should be

Me.pgTelephone.Visible = False (or TRUE)


I would have used the Select Case() function instead of the If() function.

HTH
 
R

RobUCSD

Thanks, I works now. I am pretty much a rookie, I tried select case and
couldn't make it work. If you have time I would love to see how it works with
this example. Thanks, Rob
 
S

SteveS

Maybe this will work for you. I created an unbound form and added some
controls.

I modified your code...in each option, you were only showing one control. So
hide all first, then unhide the one you want.

Here is the code: (watch for line wrap in the error code)

'--------------------------------
Private Sub lstVisit_GotFocus()
On Error GoTo lstVisit_GotFocus_Error

Me.Form.AllowEdits = True
Me.Refresh

Dim T_Visit As String

T_Visit = Me.VisitType

'first hide all controls
Me.pgAblations.Visible = False
Me.pgCardioversions.Visible = False
Me.pgClinicVisits.Visible = False
Me.pgDevices.Visible = False
Me.pgTilts.Visible = False
Me.pgTelephone.Visible = False

'now show one control
Select Case T_Visit

Case "Ablation"
Me.pgAblations.Visible = True

Case "Device"
Me.pgDevices.Visible = True

Case "Clinic"
Me.pgClinicVisits.Visible = True

Case "Cardioversion"
Me.pgCardioversions.Visible = True

Case "Telephone"
Me.pgTelephone.Visible = True

Case "Tilt Table"
Me.pgTilts.Visible = True

End Select

On Error GoTo 0
Exit Sub

lstVisit_GotFocus_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
lstVisit_GotFocus of VBA Document Form_frmVisitNewEdit"

End Sub
'--------------------------------


HTH
 
R

RobUCSD

Thanks Steve, I see how the select case works now, I am changing my code over
to this and I can use it in the future. Thanks and have a great day. Rob
 

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

Similar Threads

Select Case problem 1
Nasty Error 94 msg 10
If...Then...Else 1
If Then Else 3
why is my form dirty? 6
Do not want subform to update 16
Hide label for null results 6
First Report always "true" 3

Top