Datasheet Error #Name?

  • Thread starter CHARLES.CLAYTON
  • Start date
C

CHARLES.CLAYTON

A2K

I have a form with several tabs. One of the tabs takes a crosstab and
summarizes the data. Since the data will change over time I have a
maximum of 7 columns for the form and the crosstab will not always use
all of them. Consequently, I get the error "#Name?" for those columns
that do not presently exist in the crosstab. I know that I can hide
those columns on the form but I was wondering if there was a way to
trap for this error so that when the form loaded, it would show the
correct number of columns? That way I never have to worry about either
hiding or unhiding columns.

Thanks,

Charles D Clayton Jr

PS - I have minimal coding abilities.
 
K

KARL DEWEY

No coding. Open the query in design view, click on menu VIEW - SQL View.
In the last line of the SQL statement you will see something like this --
PIVOT Staff.Initials;
Staff is the table name and Initials is the field name that has the column
data.

Edit it to look like this --
PIVOT Staff.Initials IN("FF","CD","JF","SF","KK");
The information in the quotes are the data stored in the field. Just
include all the possible data the will be in the query results and place it
in the order you want it displayed.
 
C

CHARLES.CLAYTON

Thanks for the suggestion. On the one hand, it will get rid of the
#Name? error which is nice but on the other hand, I have all these
blank columns with no data in them. That will be confusing to some
people. Is there a way to hide/unhide based on whether or not there is
any data in the column?

Thanks,

Charles D Clayton Jr
 
K

KARL DEWEY

I am sure there is code to hide if there is no data but you will still have
blank horizontal space. Text boxes can shrink vertically but not
horizontialy.
 
C

CHARLES.CLAYTON

I was finally able to work something out. In the Form's OnLoad event I
put this code

Private Sub Form_Load()
' Created by Charles D Clayton Jr
' May 9, 2006
' Dyamically populate Datasheet from crosstab query
'
Dim I As Integer
Dim Z As Integer
Dim rst As Recordset

Set rst = Me.Form.RecordsetClone

' Hide all columns except Iso
For I = 1 To 7
Me("txt" & I).ColumnHidden = True
Next

' Ignore 1st four columns (Iso, Sheet, Service, Line)
' Unhide those columns that have data
On Error Resume Next
For I = 1 To rst.Fields.Count - 4
Z = I + 4
Me("txt" & I).ColumnHidden = False
Me("txt" & I).ControlSource = rst.Fields(Z).Name
Me("lbl" & I).Caption = "Rev " & I - 1
Next

' Clean up
Set rst = Nothing
End Sub

In my form I have 8 text and label boxes (txt1, lbl1, txt2, lbl2, etc.)
plus one for the drawing (txtIso). txtIso remains unhidden but I hide
all remaining text and label boxes. I determine how many fields of
data are in the crosstab query and then subtract four since for my
query I have 5 rows with the 1 column and 1 value. Finally I unhide
the columns that have values.

Hopefully several people more experienced than me will look at the code
and make some suggestions on how to improve/correct it.

Blessings,

Charles D Clayton Jr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top