473,500 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Report based on a Crosstab Query

I have a report that is based upon a crosstab query which return only the
columns (fields) it has data for. When my report runs it sometimes fails
because some of the text boxes don't have a field in the query. I've
written some code to "fake" the missing field names which works perfectly
but is quite complex and I'm wondering if there's a simple light bulb
shining somewhere that I'm missing. The field names returned by the
crosstab are 0, 1, 2, 3, 4 and 5. Here's my code (don't laugh):

On Error GoTo errTrap
Const cProcedure = "Report_Open"

'The record source is a crosstab query which returns only the fields it has
data for so
'we need to fake the field names that are missing

Dim db As DAO.Database, rs As DAO.Recordset, strField As String

'Declare boolean flags to indicate whether or not a field name has been
established
Dim bln0Set As Boolean, bln1Set As Boolean, bln2Set As Boolean, bln3Set As
Boolean, bln4Set As Boolean, bln5Set As Boolean

'strField must not be empty at start
strField = "x"
Set db = CurrentDb
Set rs = db.OpenRecordset(Me.OpenArgs)

With rs
.MoveFirst
Do Until .EOF

If (Not IsNull(![0])) And bln0Set = False Then
If strField <"" Then
strField = "0" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln0Set = True 'Set to true once field name has been set
End If
Me.txtLevel0.ControlSource = strField
strField = "x" 'Fill the string ready for next usage
End If

If (Not IsNull(![1])) And bln1Set = False Then
If strField <"" Then
strField = "1" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln1Set = True
End If
Me.txtLevel1.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![2])) And bln2Set = False Then
If strField <"" Then
strField = "2" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln2Set = True
End If
Me.txtLevel2.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![3])) And bln3Set = False Then
If strField <"" Then
strField = "3" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln3Set = True
End If
Me.txtLevel3.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![4])) And bln4Set = False Then
If strField <"" Then
strField = "4" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln4Set = True
End If
Me.txtLevel4.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![5])) And bln5Set = False Then
If strField <"" Then
strField = "5" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln5Set = True
End If
Me.txtLevel5.ControlSource = strField
strField = "x"
End If

.MoveNext
Loop
End With

Exit Sub

errTrap:
If Err.Number = 3265 Then
strField = ""
Resume Next 'Trap the error produced when the field doesn't exist
Else
Call libErrorHandler(Me.Name, cProcedure)
End If
Nov 3 '06 #1
2 2903
Open the crosstab in design view.
In the Properties box, type all the possible values beside the Column
Headings property.

The query now has those columns (and only those columns), regardless of
whether there is data for them or not, so the report will be fine.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Keith Wilby" <he**@there.comwrote in message
news:45**********@glkas0286.greenlnk.net...
>I have a report that is based upon a crosstab query which return only the
columns (fields) it has data for. When my report runs it sometimes fails
because some of the text boxes don't have a field in the query. I've
written some code to "fake" the missing field names which works perfectly
but is quite complex and I'm wondering if there's a simple light bulb
shining somewhere that I'm missing. The field names returned by the
crosstab are 0, 1, 2, 3, 4 and 5. Here's my code (don't laugh):

On Error GoTo errTrap
Const cProcedure = "Report_Open"

'The record source is a crosstab query which returns only the fields it
has data for so
'we need to fake the field names that are missing

Dim db As DAO.Database, rs As DAO.Recordset, strField As String

'Declare boolean flags to indicate whether or not a field name has been
established
Dim bln0Set As Boolean, bln1Set As Boolean, bln2Set As Boolean, bln3Set As
Boolean, bln4Set As Boolean, bln5Set As Boolean

'strField must not be empty at start
strField = "x"
Set db = CurrentDb
Set rs = db.OpenRecordset(Me.OpenArgs)

With rs
.MoveFirst
Do Until .EOF

If (Not IsNull(![0])) And bln0Set = False Then
If strField <"" Then
strField = "0" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln0Set = True 'Set to true once field name has been set
End If
Me.txtLevel0.ControlSource = strField
strField = "x" 'Fill the string ready for next usage
End If

If (Not IsNull(![1])) And bln1Set = False Then
If strField <"" Then
strField = "1" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln1Set = True
End If
Me.txtLevel1.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![2])) And bln2Set = False Then
If strField <"" Then
strField = "2" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln2Set = True
End If
Me.txtLevel2.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![3])) And bln3Set = False Then
If strField <"" Then
strField = "3" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln3Set = True
End If
Me.txtLevel3.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![4])) And bln4Set = False Then
If strField <"" Then
strField = "4" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln4Set = True
End If
Me.txtLevel4.ControlSource = strField
strField = "x"
End If

If (Not IsNull(![5])) And bln5Set = False Then
If strField <"" Then
strField = "5" 'Only assign the value to the string if the
"no field" error hasn't occurred
bln5Set = True
End If
Me.txtLevel5.ControlSource = strField
strField = "x"
End If

.MoveNext
Loop
End With

Exit Sub

errTrap:
If Err.Number = 3265 Then
strField = ""
Resume Next 'Trap the error produced when the field doesn't exist
Else
Call libErrorHandler(Me.Name, cProcedure)
End If


Nov 3 '06 #2
"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:45**********************@per-qv1-newsreader-01.iinet.net.au...
Open the crosstab in design view.
In the Properties box, type all the possible values beside the Column
Headings property.

The query now has those columns (and only those columns), regardless of
whether there is data for them or not, so the report will be fine.
Blimey, that's embarrassingly simple, can't you tell I've never used
crosstabs before? Many thanks Allen.

Regards,
Keith.
Nov 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7535
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
17626
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
3
3331
by: Edward | last post by:
ACCESS 2k I need to design a report based on a rota system for staff at various shops. The data is effectively stored in a single table, along the lines of: Initials (e.g. BH, FG, RM etc.)...
4
2074
by: No Spam | last post by:
Dear Access 2000 users, I have a crosstab query that puts together certain information perfectly. It has a criteria that is based on a form that limits how many columns are returned based on...
15
4383
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
3
3399
by: Bryan | last post by:
I've been looking over this newsgroup, but I can't find an answer to my problem. I see that a few others have posted this issue over the years, but none of them got a response. I'll give it...
2
1860
AccessIdiot
by: AccessIdiot | last post by:
Hello all, I have a report that is based on a crosstab query. One of the fields in the crosstab query is based on a query. It is a coded value. When I look at the crosstab query it displays the...
6
3153
kcdoell
by: kcdoell | last post by:
Hello: I have a report that is based on the following crosstab query: SELECT tblProduct.ProductName, QryProd_Bud.GWP_BUD, Nz(,0) AS Week_1, Nz(,0) AS Week_2, Nz(,0) AS Week_3, Nz(,0) AS Week_4,...
14
7825
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.