VBA - Problem formatting a sub form in a report

12 views Asked by At

I'm a newbie to VBA and have an issue with formatting a sub form on a report. I have been able to make it work on a regular report without a sub form. I have the following code in the “TDate Header” section in my report and using the “OnFormat” event.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) 
Dim myColor1 As Long 
Dim myColor2 As Long myColor1 = RGB(249, 237, 237) 'LysLysRød #F9EDED 
myColor2 = RGB(255, 255, 255) 'Hvit #EAEDF2     
If Me.TDate > Date Then        
Me.Detail.BackColor = myColor1     
Else          
Me.Detail.BackColor = myColor2     
End If 
End Sub

This works very well; Preview

However, I am struggling big time with a different report which has a sub form. The “On Format” event is not available in the sub form as it was in the code above.

I tried to use the “OnPaint” event, but I don’t see anything when I click print preview.

Private Sub Detail_Paint()     
Dim myColor1 As Long     
Dim myColor2 As Long     
myColor1 = RGB(249, 237, 237) 'LysLysRød #F9EDED     
myColor2 = RGB(255, 255, 255) 'Hvit #EAEDF2         
If Me.TDate > Date Then            
Me.Detail.BackColor = myColor1         
Else            
Me.Detail.BackColor = myColor2         
End If     
End Sub

Then I tried to put the code in the “OnLoad” event (and a couple of other places as well in the report itself, but I can’t get it to work. One issue is that I am unable to refer to the sub forms back color. My Report is called “rptHolesWithWindarrow”. My sub form on the report is called “sfrmTourneyWindArrow”. Checking online I see thet the way to refere to a sub form is Forms![FormName]![SubformName].Form![ControlName]. But I have a sub form on a report and am wondering if that can be the issue or if it is something else?

I have tried variations like; Reports!rptHolesWithWindarrow!sfrmTourneyWindArrow.Forms!Detail.BackColor Reports!rptHolesWithWindarrow!sfrmTourneyWindArrow.Reports!Detail.BackColor Reports!rptHolesWithWindarrow!sfrmTourneyWindArrow.Forms!BackColor Reports!rptHolesWithWindarrow!sfrmTourneyWindArrow.Reports!BackColor I have managed to get the Conditional Formatting to work on the control, but not able to change the background color. Any help will be much appreciated.

0

There are 0 answers