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!

VBA Behind a Report Problem

Status
Not open for further replies.

Ray1127

Programmer
Feb 22, 2002
231
0
0
US
I have several Access 2010 Reports. All have some Code behind the report for various reasons. One Report is give me a problem. I'm trying to set the backcolor of the Detail section depending on the results from 2 boolean fields. There are only 3 results that mean anything though. If 1 is True the other is irrelevant if that one is true then it depends on the second. So I put this code in the Detail section

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Not me.enrolled Then
detail.backcolor = vbYellow
Else
If Not Me.current Then
detail.backcolor = vbRed
Else
detail.backcolor = vbGreen
End if
End if

End Sub

Everytime I try to save this I get the following Error This form or report contains changes that are incompatible with the current database format. The form or report was not saved.

I tried adding those 2 fields to the detail section, changed the name of the controls and changed the if statement accordingly. Got the same result. Don't under stand why. The report is based on a query and there is 1 Group Header and the detail. Anybody have an Idea? This is Access 2010.

 
Have you enabled code?

I would bind enrolled and current to text boxes in the detail section txtEnrolled and txtCurrent. Then try this code:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  If Not me.txtEnrolled Then 
    Me.Section(0).backcolor = vbYellow
   Else
    If Not Me.txtCurrent Then
         Me.Section(0).backcolor = vbRed
     Else
         Me.Section(0).backcolor = vbGreen
    End if
  End if
End Sub
Do you understand that every section would have a colored background?

Duane
Hook'D on Access
MS Access MVP
 
Yes I have other reports in the same DB that have code and work fine. Yes, I want every section to have a colored background. The users will only look at this particular report on screen and their request is that it be visually obvious which record is of those types.

I did bind those 2 controls to text boxes as you suggested that was what I meant in the last statement in my original Message.

Yes the HasModule is set to yes. I also took everything out and but in the following as the only line of code in the Detail Section Format event.

Cancel = True

Got the same error message when I tried to save the report. Doesn't matter what I put in the VBA behind this report get the same error message. Other reports are fine it's just this one. It's a very simple report. That's what I don't get. It's 1 query that pulls all of the data from 2 Tables. One table is demographic information and the other is specific to what this DB is used for. So the Data elements are case type, case enrollment date case disenrollment date and member name, address, DOB

That's it.
 
Sounds like there might be some corruption in the report. I would probably create a new, blank report and begin adding stuff back in like Record Source, sections, controls, and finally code. You should be able to copy and paste most of this.

Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane hadn't thought of that the report runs fine just can't add VBA to the report. Never thought about possible corruption. I did a partial fix in that I put check boxes on a form that calls the report and set the Query to look at those checkboxes to limit the data appropriately. It works but if there is no data the report displays with errors.

I'll get started on recreating the report and let you know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top