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!

Make Fields Visible or Not Visible

Status
Not open for further replies.

TheTomCat

Programmer
Aug 25, 2004
73
0
0
US
I am working on a Time Sheet (r_TimeSheet). If an employee has overtime (time and a half), I want it to print the Overtime total (OTTotal), and any extra regular hours. I have that working fine. The problem is when you come up with Negative overtime. Then I want it to NOT print the Negative number. I created another field (OtherRegluar2) and have it totaling the Negative number and RegularHours.
When I print the Time Sheet, I want it to, if positive overtime, to print the Overtime total and Regular Hours. If Overtime is Negative, I want it to hide the Overtime Total and Regular Hours and show OtherRegular2. I have the below code working if it's Negative, It hides OTTotal and RegularHours. But when OTTOtal is a positive number, It does not hide anything. In the below code, the first half seems to work but the second half (after Else) does NOT. Does anyone see anything wrong with this code?

If OTTotal < 0 Then
Report_r_TimeSheet.OTTotal.Visible = False
Report_r_TimeSheet.RegularHours.Visible = False
Report_r_TimeSheet.OtherRegular2.Visible = True
Else
If OTTotal > 0 Then
Report_r_TimeSheet.OtherRegular2.Visible = False
Report_r_TimeSheet.OTTotal.Visible = True
Report_r_TimeSheet.RegularHours.Visible = True

End If


Thomas Bailey
a/k/a TomCat
 
You have 2 If and only 1 End If. Can you paste your complete code using TGML markup? If your are referencing controls of a report from code in the report, you should be able to use the more conventional "Me." syntax:

Code:
If Me.OTTotal < 0 Then
    Me.OTTotal.Visible = False
    Me.RegularHours.Visible = False
    Me.OtherRegular2.Visible = True 
 Else
    If Me.OTTotal > 0 Then
        Me.OtherRegular2.Visible = False
        Me.OTTotal.Visible = True
        Me.RegularHours.Visible = True
    End If


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Soryy....here is the complete code.

Private Sub PrntTimeSheet_Click()
If OTTotal < 0 Then
Report_r_TimeSheet.OTTotal.Visible = False
Report_r_TimeSheet.RegularHours.Visible = False
Report_r_TimeSheet.OtherRegular2.Visible = True
Else
If OTTotal > 0 Then
Report_r_TimeSheet.OtherRegular2.Visible = False
Report_r_TimeSheet.OTTotal.Visible = True
Report_r_TimeSheet.RegularHours.Visible = True

End If
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[TimeSheetID] = " & Me.[TimeSheetID]
DoCmd.OpenReport "r_TimeSheet", acViewNormal, , strWhere
End If
End If
End Sub


Thomas Bailey
a/k/a TomCat
 
There are more appropriate TGML markups than bold. Please use the Code TGML for code so indents are maintained and font is monospaced.

Code:
Private Sub PrntTimeSheet_Click()
    If OTTotal < 0 Then
        Report_r_TimeSheet.OTTotal.Visible = False
        Report_r_TimeSheet.RegularHours.Visible = False
        Report_r_TimeSheet.OtherRegular2.Visible = True 
      Else
        If OTTotal > 0 Then
            Report_r_TimeSheet.OtherRegular2.Visible = False
            Report_r_TimeSheet.OTTotal.Visible = True
            Report_r_TimeSheet.RegularHours.Visible = True
        End If 
        Dim strWhere As String 
        If Me.Dirty Then 'Save any edits.
            Me.Dirty = False
        End If
        If Me.NewRecord Then 'Check there is a record to print
            MsgBox "Select a record to print"
          Else
            strWhere = "[TimeSheetID] = " & Me.[TimeSheetID]
            DoCmd.OpenReport "r_TimeSheet", acViewNormal, , strWhere
        End If
    End If 
End Sub

So, if I understand correctly, you are using code in a form to manage visibility of control on a report but the report isn't opened until after the visible properties are set?

Typically you would add this type of code to the report section On Format events. Is there a reason why you don't have the code in the report?

What do you want to see if the OTTotal = 0?



Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
You can shorten the code by
Private Sub PrntTimeSheet_Click()
with Report_r_TimeSheet
.OTTotal.Visible = (OTTotal > 0)
.RegularHours.Visible = (OTTotal > 0)
.OtherRegular2.Visible = (OTTotal < 0)
end with
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[TimeSheetID] = " & Me.[TimeSheetID]
DoCmd.OpenReport "r_TimeSheet", acViewNormal, , strWhere
End If
End Sub
But I am also confused because if the report is not open you cannot manage those properties.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top