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

MS Visual Basic Code Help

Status
Not open for further replies.

eebabe

IS-IT--Management
Jul 17, 2003
54
0
0
US
I'm trying to show these titles when month number is input. When number 1 to 6 is entered all the months is visible but when number >=7 is entered JUL to DEC is not visible. Where did the code go wrong. Help..

Also if there is more elegant way of coding this that would be great. Thanks.

The months are displayed

JUL AUG SEPT OCT NOV DEC JAN FEB MAR APR MAY JUN

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
If (Me.MoInput >= 1 And Me.MoInput <= 6) Then
Me.JUL_TITLE.Visible = True
Me.AUG_TITLE.Visible = True
Me.SEP_TITLE.Visible = True
Me.OCT_TITLE.Visible = True
Me.NOV_TITLE.Visible = True
Me.DEC_TITLE.Visible = True
Me.JAN_TITLE.Visible = True
If (Me.MoInput >= 2 And Me.MoInput <= 6) Then
Me.FEB_TITLE.Visible = True
If (Me.MoInput >= 3 And Me.MoInput <= 6) Then
Me.MAR_TITLE.Visible = True
If (Me.MoInput >= 4 And Me.MoInput <= 6) Then
Me.APR_TITLE.Visible = True
If (Me.MoInput >= 5 And Me.MoInput <= 6) Then
Me.MAY_TITLE.Visible = True
If (Me.MoInput = 6) Then
Me.JUN_TITLE.Visible = True
If (Me.MoInput >= 7) Then
Me.JUL_TITLE.Visible = True

End If
End If
End If
End If
End If
End If
End If
End Sub
 
Your first if statement will not make any thing visible that is outside the range of Me.MoInput 1 to 6. That would be a start. Even though I think JUL should be visible, but not sure of the nesting of the if statements.
 
I don't know what you are trying to actually do with your code since it is hard to read without the TGML Code tag. I think you might be able to use this:

Code:
Dim intMth as Integer
For intMth = 1 to 12
[COLOR=#EF2929][highlight #FCE94F]    'if the month number is less than or equal to MoInput, make it visible[/highlight][/color]
    Me(MonthName(intMth,True) & "_Title").Visible = (intMth <= Me.MoInput)
Next

Duane
Hook'D on Access
MS Access MVP
 
It's hard to follow your code because you embedded it in your text (which removes spaces and indents). Try using the code button <> to reserve the formatting in the future.

Also, I think the following code might do what you want:
Code:
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
 For i = 1 To 12
    mo = Me.MoInput + i - 1
    If mo > 12 Then mo = 1
    Title = Choose(mo, Me.JAN_TITLE, Me.FEB_TITLE, Me.MAR_TITLE, Me.APR_TITLE, Me.MAY_TITLE, Me.JUN_TITLE, Me.JUL_TITLE, Me.AUG_TITLE, Me.SEP_TITLE, Me.OCT_TITLE, Me.NOV_TITLE, Me.DEC_TITLE)
    Title.Visible = True
 Next i
 End Sub

This will turn on the titles from Jan to Dec, depending on the starting Month inputted. It's is defaulting to start at January when Me.MoInput = 1. If you want it to start at a different month, change the -1 in the formula: mo = Me.MoInput + i - 1 to 0=Feb, +1=March, +2=April ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top