I'm at the point where I'd pay someone good money out of my own pocket to make this work. -_- I have a crosstab query that has different numbers of columns depending on one field in the query, called "Sequence". Depending on the value of Sequence (an integer), there could be anywhere from 3 to 15 columns.
I'm trying to create a report from VBA code using DAO to find out how many columns there will be, and then adding the code to add the extra fields in the Detail section of the module behind the Report as well as name the columns (they will be different in each report depending on the "Sequence"). There are a few "common" text fields that the report will have regardless of the value of sequence. Problem is, I get the error "You must be in Design view to create or modify controls." So I tried hard coding the control creation into a module, limiting myself to 20 columns. The code is starting to get pretty darn ugly, in my opinion, and I still think using this method I'll be unable to accomplish my goal.
I've been given other "solutions" to this problem which basically entails having columns that are hidden depending on the results of the query. This is fine when you run a report that is using, say, names of months or something that is already set. The wrinkle here is that the names of the columns change also; they are NOT the same from Sequence to Sequence, so having a standard report and then programmatically hiding columns will not work for me.
So I decided to come here and ask the question, how do I programmatically add controls to a report based on the information from a query in the setup I've described above? I'd post the code I have so far but there's a lot of it and I don't think it would help. If you know what I'm doing then I'm guessing you probably won't need to see it.
Here's the code behind the module when the Sequence needs three columns:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer) Set lblLabel1 = CreateReportControl(strReportName, acLabel, acDetail, , , 60, 60, 5100, 600) lblLabel1.Name = "lblLabel1_Label"
Set ctlText3 = CreateReportControl(strReportName, acTextBox, acDetail, , "", Left:=(intDataX), Top:=intDataY) ctlText3.Name = "ctlText3" End Sub
That's where I get that error about being in Design View.
I would happily give all my points to anyone that can help me arrive at a solution to this. I left out the references to the values of the Text fields; that will be my next "thingy" to tackle, passing the information in the recordset from one module to the other. Of course, ignore the positional elements in the code as well, they change as I work on formatting.
To get the points I expect to be given enough information to be able to create a report that will have a variable number of columns. What would really be extra-nifty is if the report would be able to work based on grouping by "Sequence", such that based on the query behind the report when the Sequence number changed, the report would be able to switch the number of columns.
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
The Grade of the Solution
The Zone Rank of the Expert Providing the Solution
The Number of Author and Expert Comments
The Number of Experts Contributing
The Feedback of the Community
Your Input Matters Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.
If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.