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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide controls based on selection from Option Group

Status
Not open for further replies.

azalealee

Programmer
Nov 21, 2002
36
AU
Hi!

I have a form with 4 options in an option group. I would like 2 textboxes and their labels to appear only when option 4 is selected. I have written the following code, but the error "..only comments may appear after End Sub, End Function..." occurs. I have also tried a Select Case approach, but I get a similar error. Any help would by appreciated!

Private Sub Filter_Op_Group_AfterUpdate()
Dim optionNumber As String
optionNumber = Forms!F_ReportsMenu!Filter_Op_Group
If optionNumber = 4 Then Call showdates
End If
End Sub

Private Sub Form_Load()
Call hidedates
End Sub

Private Sub showdates()
Me.FromDate.Visible = True
Me.FromLabel.Visible = True
Me.ToDate.Visible = True
Me.ToLabel.Visible = True
End Sub

Private Sub hidedates()
Me.FromDate.Visible = False
Me.FromLabel.Visible = False
Me.ToDate.Visible = False
Me.ToLabel.Visible = False
End Sub
 
Hi,

I have run your code several times and different ways. So far, I have not had any problems. I have a feeling there is something else in your code window that is not showing here. The error msg you referenced normally shows up when there are words entered outside the procedure. Take a close look and be sure you dont have an end sub or end function lurking somewhere.

Have A Great Day!!!,

Nathan
Senior Test Lead
 
Hi

Took your advice and had a look around. Deleted an old sub for a command button that I removed before, ran it again and came up with a different message: " Compile error: End If without block If" with the End If on the Filter_Op_Group_AfterUpdate() highlighted.

Something wrong with my If statement?

Thanks for your help.

Azalea
 
Hi
Finally fixed the problem. Got rid of the If statement and used a Select Case again. I'm pretty sure the problem was the sub for the command button I deleted earlier thanks to your advice. This was the code that worked:

Private Sub Filter_Op_Group_AfterUpdate()
Select Case Me![Filter_Op_Group]
Case 1
Call hidedates
Case 2
Call hidedates
Case 3
Call hidedates
Case 4
Call showdates
End Select
End Sub

Private Sub Form_Load()
Me.ReportTitle = ""
Call hidedates
End Sub

Private Sub showdates()
Me.FromDate.Visible = True
Me.FromLabel.Visible = True
Me.ToDate.Visible = True
Me.ToLabel.Visible = True
End Sub

Private Sub hidedates()
Me.FromDate.Visible = False
Me.FromLabel.Visible = False
Me.ToDate.Visible = False
Me.ToLabel.Visible = False
End Sub

Thanks for your help.

Regards
Azalea
 
HI,

I am glad it worked for you. The problem with the If statement was that you didnt need a "End If" if you are calling a sub which you were.

Private Sub Filter_Op_Group_AfterUpdate()
Dim optionNumber As String
optionNumber = Forms!F_ReportsMenu!Filter_Op_Group
If optionNumber = 4 Then Call showdates <--calling sub or function
End If <--- dont need
End Sub

Hope that helps. Have A Great Day!!!,

Nathan
Senior Test Lead
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top