|
Question : NAME? in fields on crosstab query subform
|
|
I have three crosstab querys that are run in SQL in a sub procedure. THe results are then output to subforms. All fields on the subforms are bound but the record source is not defined. I had to do this for it to work. NAME? appears in fields that do not return a value in the query. In access the query works fine. I also have a similar query output to a graph. this works fine also.
The unique qualities here seem to be that a)it is a crosstab query b)I am using a date range specified in fields on the main form c)I am specifing the user name from a field on the main form
The fields in the other subforms on the main form are populated by select queries and do not have this problem.
Brewdog started to look at this yesterday. Now open as new question.
Any help appreciated.
Sicando
Dim strSQL As String, strEngName As String, dteFirst As Date, dteSecond As Date, recClone As Recordset
If IsNull(Me.cmbEngName) Or IsNull(Me.dteEnd) Or IsNull(Me.dteStart) Then MsgBox "Please complete all field before continuing", vbOKOnly, "KPI Error" Exit Sub Else
If Not IsDate(Me.dteEnd) Or Not IsDate(Me.dteStart) Then MsgBox "Incorrect date input...Please try again", vbOKOnly, "KPI Error" Exit Sub End If strEngName = Me.cmbEngName dteFirst = Me.dteStart dteSecond = Me.dteEnd 'Forms!frmkpi1!subformKPIAPZCODES.Form.Visible = True
strSQL = "TRANSFORM Count(BASEPLAN.SORTCODE) AS CountOfSORTCODE" _ & " SELECT CONTROL1.PROJ_ENG" _ & " FROM BASEPLAN INNER JOIN CONTROL1 ON BASEPLAN.SORTCODE = CONTROL1.SORTCODE" _ & " WHERE CONTROL1.ABPACK Between #" & Format(dteFirst, "mm\/dd\/yy") & "# And #" & Format(dteSecond, "mm\/dd\/yy") & "#" _ & " AND CONTROL1.PROJ_ENG = '" & strEngName & "'" _ & " GROUP BY CONTROL1.PROJ_ENG " _ & " PIVOT BASEPLAN.APZ"
Forms!frmkpi1!subformKPIAPZCODES.Form.RecordSource = strSQL
Set recClone = Forms!frmkpi1!subformKPIAPZCODES.Form.RecordsetClone
If recClone.EOF Then Forms!frmkpi1!subformKPIAPZCODES.Visible = False Forms!frmkpi1!lblAPZ.Visible = True recClone.Close Else Forms!frmkpi1!subformKPIAPZCODES.Visible = True Forms!frmkpi1!lblAPZ.Visible = False recClone.Close
|
|
Answer : NAME? in fields on crosstab query subform
|
|
Name? indicates that the field has as an invalid source.
When you are restricting the output of the query by inserting criterias you may not get all the columns you expect in return. This means that when your subform has a field refering column "SomeValue" and "SomeValue" is not represented in the resulting set of data, the form will report an error.
The solution is to "force" the columns (property Column Headings when in design mode of the query). This will reduce the "live effect" of the crosstab, but your subform is already refering a fixed set of columns anyway, so that does not represent a problem. To make sure that you get the columns you expect change your code to this.
strSQL = "TRANSFORM Count(BASEPLAN.SORTCODE) AS CountOfSORTCODE" _ & " SELECT CONTROL1.PROJ_ENG" _ & " FROM BASEPLAN INNER JOIN CONTROL1 ON BASEPLAN.SORTCODE = CONTROL1.SORTCODE" _ & " WHERE CONTROL1.ABPACK Between #" & Format(dteFirst, "mm\/dd\/yy") & "# And #" & Format(dteSecond, "mm\/dd\/yy") & "#" _ & " AND CONTROL1.PROJ_ENG = '" & strEngName & "'" _ & " GROUP BY CONTROL1.PROJ_ENG " _ & " PIVOT BASEPLAN.APZ In (""ExpectedColumn1"",""ExpectedColumn2"",""etc."")"
|
|
|
|