If Statement in Visual Basic

jessabridge

Registered User.
Local time
Today, 15:37
Joined
Jun 29, 2011
Messages
35
I have:
Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Overtime = 0 Then
Me.OT.BackColor = vbBlack
Me.OT.Visible = False
End If
End Sub
And it is working, but:
I need 5 other statements like this that are not contingent on each other.

If Me.Personal_DayTable = 0 Then
Me.P.BackColor = vbBlack
Me.P.Visible = False
End If

Is it even possible? My first time in Basic...shocked I got one to run. :D
Thanks in advance!
Jessa

PS...I just nothice the "if" only worked on the first data subset... So, I guess I don't want the "if" to end....is that possible?
 
Last edited:
You can have multiple blocks in the sub:

If Whatever
...
End If

If SomethingElse
...
End If
 
This ended up working...But your advice set me on the right path, so thanks!

Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Overtime = 0 Then
Me.OT.Visible = False
Else: Me.OT.Visible = True
End If
If Me.RegularHours = 0 Then
Me.Hrs.Visible = False
Else: Me.Hrs.Visible = True
End If
If Me.SickDayTable = 0 Then
Me.S.Visible = False
Else: Me.S.Visible = True
End If
If Me.VacationDayTable = 0 Then
Me.V.Visible = False
Else: Me.V.Visible = True
End If
If Me.PersonalDayTable = 0 Then
Me.P.Visible = False
Else: Me.P.Visible = True
End If
If Me.PersonalDayTable = 0 Then
Me.P.Visible = False
Else: Me.P.Visible = True
End If
If Me.HolidayTable = 0 Then
Me.Holiday.Visible = False
Else: Me.Holiday.Visible = True
End If
If Me.R0R1DayTable = 0 Then
Me.R0orR1.Visible = False
Else: Me.R0orR1.Visible = True
End If
End Sub

Jessa
 
No problem. I should have noticed you'd need the Else clause.
 

Users who are viewing this thread

Back
Top Bottom