INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Make Fields Visible or Not Visible

Make Fields Visible or Not Visible

(OP)
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

RE: Make Fields Visible or Not Visible

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 --> vba

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

RE: Make Fields Visible or Not Visible

(OP)
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

RE: Make Fields Visible or Not Visible

There are more appropriate TGML markups than bold. Please use the Code TGML for code so indents are maintained and font is monospaced.

CODE --> vba

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

RE: Make Fields Visible or Not Visible

You can shorten the code by

Quote:

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close