Column Names not in Table

jcbhydro

Registered User.
Local time
Today, 11:49
Joined
Jul 26, 2013
Messages
187
Good Morning,

I have 2 or 3 Queries which are run specifically export data to an Excel file required by external agencies.
The queries contain column headings, required by the agencies, which are not derived from Table fields. Obviosly, no record data is produced for these columns.

When the queries are run, the dreaded 'Enter Parameter Value' message appears for each to the additional column headings.

The following is a copy of the SQL Code for one such Query;
SELECT DISTINCTROW [Name1] AS Title, [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2] AS [Aggregated Donations], [Name3] AS [Sponsored Event], [Mail List].SubDate, Sum([Mail List].[£ Recd]) AS [SumOf£ Recd]
FROM [Mail List]
GROUP BY [Name1], [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2], [Name3], [Mail List].SubDate, [Mail List].[Gift Aid]
HAVING ((([Mail List].SubDate)>#4/4/2014# And ([Mail List].SubDate)<#4/6/2015#) AND (([Mail List].[Gift Aid])=True));

Is there not some way in which these columns can be defined in Property Sheet such that this error message is prevented?

Any suggestions would be most welcome.

Regards,

jcbhydro
 
If you want to add a column for some text then:
Code:
"" AS [ANewColumnName]
When number then:
Code:
Null AS [ANewColumnName]
 
Many thanks for comment.
I have modified the code in design view as follows, but I susspect that I have not correctlly interpreted your suggestion.

Modified code is;

SELECT DISTINCTROW [Name1] AS Title, [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2] AS [Aggregated Donations], [Name3] AS [Sponsored Event], [Mail List].SubDate, Sum([Mail List].[£ Recd]) AS [SumOf£ Recd]
FROM [Mail List]
GROUP BY [Name1], [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2], [Name3], [Mail List].SubDate, [Mail List].[Gift Aid]
HAVING ((([Name1]) Is Null) AND (([Name2]) Is Null) AND (([Name3]) Is Null) AND (([Mail List].SubDate)>#4/5/2014# And ([Mail List].SubDate)<#4/6/2015#) AND (([Mail List].[Gift Aid])=True));

Regards,

jcbhydro
 
Many thanks for comment.
I have modified the code in design view as follows, but I susspect that I have not correctlly interpreted your suggestion.
No you haven't, I'll make a sample so you can get the idea of how it works:
Create a new query and put the below in it, remember to change YouTableName to a table name in your database.
Code:
Select "" as [ANewColumnNameWithText], Null AS [ANewColumnNameWithNumber] From YouTableName
 
Hi JHN,

I have amended code as you suggest, but I'm obviously still not geting right because I conyine to get the 'Parameter Error#message.

Here is the amended code,

I am obviously still getting it wrong
SELECT DISTINCTROW [Name1] AS Title, Null AS Name1, [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2] AS [Aggregated Donations], Null AS Name2, [Name3] AS [Sponsored Event], Null AS Name3, [Mail List].SubDate, Sum([Mail List].[£ Recd]) AS [SumOf£ Recd]
FROM [Mail List]
GROUP BY [Name1], [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2], [Name3], [Mail List].SubDate, [Mail List].[Gift Aid]
HAVING ((([Mail List].SubDate)>#4/5/2014# And ([Mail List].SubDate)<#4/6/2015#) AND (([Mail List].[Gift Aid])=True));

Any fuerther suggestions?

Regards,

jcbhydro
 
it may be because you are using HAVING rather than WHERE. HAVING is used when you use criteria on an 'aggregated' column after grouping, WHERE works on the 'raw data' before grouping.

In the query grid, bring the subdate and giftaid fields down again in new columns, change the GROUP BY for these two columns to WHERE and move your criteria from the grouped columns to these two columns - this link explains more-
http://stackoverflow.com/questions/287474/

incidentally, not sure if this is intended, but your query will not bring any data through since a date cannot be greater than 5th April and less than 6th April (unless it includes a time element in which case records for 5th April will be returned)
 
In addition to what CJ_London writes, I would use names that you don't have in your table.
SELECT DISTINCTROW [Name1] AS Title, Null AS Name1, [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2] AS [Aggregated Donations], Null AS Name2, [Name3] AS [Sponsored Event], Null AS Name3, [Mail List].SubDate, Sum([Mail List].[£ Recd]) AS [SumOf£ Recd]
FROM [Mail List] ...
Have you tried what I wrote in my last post?
Create a new query and put the
...
 
why not just design a query that works FIRST, and let access do the work.

change the column headers simply

newHeader: fielddetails

then simply (whatever the syntax is)

docmd.transferspreadsheet, outputparameter, queryname, spreadsheetname

Then have a look at the SQL to see what it actually looked like!

personally, I would generate a csv, rather than a spreadsheet. Much more controllable and reliable.

which is

docmd.transfertext, with generally similar arguments
 
Thank you CJ_London, JHB & Gemma,

I believe that I have followed CJ's suggestionn exactly, but although the Query runs, as it always has done, I still get the 'Enter Parameter Value' message.

Here is the amended code:

SELECT DISTINCTROW [Name1] AS Title, [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2] AS [Aggregated Donations], [Name3] AS [Sponsored Event], [Mail List].SubDate, Sum([Mail List].[£ Recd]) AS [SumOf£ Recd]
FROM [Mail List]
WHERE ((([Mail List].SubDate)>#4/5/2014# And ([Mail List].SubDate)<#4/6/2015#) AND (([Mail List].[Gift Aid])=True))
GROUP BY [Name1], [Mail List].[First Name], [Mail List].Surname, [Mail List].[Address 1], [Mail List].PostCode, [Name2], [Name3], [Mail List].SubDate, [Mail List].[Gift Aid];

Incidentally to answer JHB the pseudo column headings Name1 , 2 & 3 are not entries in the Table, they are merely labels for column headings.

CJ's comment re dates is not correct as the dates cover a full UK Financial year.

Re-Gemma's comment about csv files, the external agent, HMRC, requires a spreadsheet format. I know that one could import a csv file into a spreadsheet, but that would be one extra step that I wish to avoid.

Would this problem not be solvable by specifying something suitable on the Query property sheet to simulate 'OK' on error occurrence.

Regards to all,

jcbhydro
 
are you dealing with a gift aid claim, and populating an HRMC ods file?
 
..
Incidentally to answer JHB the pseudo column headings Name1 , 2 & 3 are not entries in the Table, they are merely labels for column headings.
Then you have found why you still get the 'Enter Parameter Value' message, then if you don't have a field it the table named [Name1(Or 2 or 3)] it is unknown and the 'Enter Parameter Value' occur.
Could you show how the out put should be, only the names of the columns, and the field names you've in the table Mail List.
 
Hi.

Here's the code I use to populate an HMRC ods file directly. Hope it helps


Code:
Public Function exportClaimToExcel() As Boolean
';-----------------------------
';gemma-the-husky 2015
';www.access-programmers.co.uk
';
';process to populate a HMRC ods gift aid claim, from a source query
';
';'qdet - detailed donation query
'; qname  - summary based on the above, to accumulate donations by donor
';
';I add a processed flag to the qdet query, so that if the claim exceeds 1000 lines, I can select the unprocessed lines only
';----------------------------
 
Const QDet = "the query with the detailed donation data"
Const QName = "the query with the summarised donation data based on qdet"
Const ExcelBase = 24 'the offset rows before we populate the spreadsheet. ie the spreadsheet starts at row 25
 
'I use a standard template, and copy this to a working template for each submission
Dim templatename As String
Dim templatepath As String
Dim destName As String
  
'variables to control excel
Dim xlApp As Object
Dim xlWB As Object
 
'processing variables to manage the recordset, and the excel sheet
Dim i As Long
Dim earliestdate As Date
Dim rst As Recordset
Dim excelrow As Long
Dim tclaim As Currency 'total claim value
Dim s As String
Dim counter As Long
     
    On Error GoTo Err_exportClaimToExcel
    
    'include code to select the ods file you wish to populate - templatename
     'I have removed filepicker code I use here
    templatename = "c:\mytemplate.ods"
    destname = "c:\mytemplate_today.ods" 
    
    'i copy the template to a working version 
    On Error GoTo copyfail
    FileCopy templatename, destName
    
     On Error GoTo Err_exportToExcel
  
     DoCmd.Hourglass True    
     earliestdate = DMin("PaymentDate", QDet, "[IRClaimAmount] > 0")   'evaluate the earliest claim date
 'this goes in a cell on the ods file
        
    On Error GoTo Err_exportClaimToExcel
    Set xlApp = CreateObject("Excel.Application")
        
    With xlApp
        .Visible = False         ' just update in background
        Set xlWB = .Workbooks.Open(destName)
        
        With xlWB
             With .Sheets("desired sheet name")
                        
                .Cells(13, 4).value = earliestdate
            
                counter = DCount("*", QName)
                If counter > 1000 Then
                    MsgBox ("There are claims for " & counter & " Donors but HMRC only allows 1000 records per claim form. " & _
                            "1000 rows will be processed on this claim. , " & _
                            "You will then be able to prepare a further claim for " & _
                            "additional Donors. ")
                    counter = 1000
                End If
                
                SysCmd acSysCmdInitMeter, "Processing Items (" & counter & ")", counter
                
                Set rst = CurrentDb.OpenRecordset(QName)
                excelrow = 0
                tclaim = 0
                
                While Not rst.EOF
                    excelrow = excelrow + 1
                    SysCmd acSysCmdUpdateMeter, excelrow
                    .Cells(ExcelBase + excelrow, 3).value = rst![PersonTitle]
                    .Cells(ExcelBase + excelrow, 4).value = rst![PersonInitials]
                    .Cells(ExcelBase + excelrow, 5).value = rst![PersonSurname]
              'determine whether address 1 starts with a house number, or not
                    If IsNumeric(Split(rst!Address1, " ")(0)) Then
                        .Cells(ExcelBase + excelrow, 6).value = Split(rst!PersonAddress1, " ")(0)
                    Else
                        .Cells(ExcelBase + excelrow, 6).value = rst!PersonAddress1
                    End If
                     .Cells(ExcelBase + excelrow, 7).value = rst![PersonPostCode]
                    .Cells(ExcelBase + excelrow, 8).value = Format(rst![PersonTotaldonation], "0.00")
                     .Cells(ExcelBase + excelrow, 9).value = rst![SponsoredEvent]
                     .Cells(ExcelBase + excelrow, 10).value = rst![PersonLatestDate]
                    .Cells(ExcelBase + excelrow, 11).value = Format(rst![PersonTotalclaim], "0.00")
 
                    tclaim = tclaim + rst!totalclaim
                    
                    On Error GoTo upfail
                    s = "update " & qdet & " set IRClaimprocessed = " & True & " where PersonID = " & rst!PersonID
                    CurrentDb.Execute s
                    
continue:
                    If excelrow = 1000 Then
                        MsgBox ("1000 rows have been processed, which is the maximum number permitted on a claim. " & _
                            "These rows will be now updated. You will then be able to prepare a further claim for " & _
                            "additional Donors. " & vbCrLf & vbCrLf & _
                            "The total claim for these items is: " & tclaim)
                        GoTo exitloop
                    End If
                    rst.MoveNext
                    
                Wend
                
exitloop:
                rst.close
                Set rst = Nothing
            End With
            
            'we opened the copy XL file, so just save it
            .save
        End With
        
        SysCmd acSysCmdRemoveMeter
        DoEvents
        DoCmd.Hourglass False
        .Visible = True    'make xl visible     
         Set xlWB = Nothing   ' Clear reference to workbook
     End With
    
    Set xlApp = Nothing      ' Clear reference to Excel
    
    exportClaimToExcel = True
 
 Exit_exportClaimToExcel:
    MsgBox "The spreadsheet has been created. Please review the Excel spreadsheet to confirm it is correct.  " & vbCrLf & vbCrLf & _
        "The spreadsheet is: " & templatename & _
        "The update process for this claim will now continue. " 
    'further processes are carried out on completion of the export process
    Exit Function
 
 Err_exportClaimToExcel:
    MsgBox ("Error: " & err & "    Desc: " & err.description)
    Resume exitfail
  
 copyfail:
    MsgBox "Sorry. We were unable to copy the template to today's claim. Please ensure the template file is not open in Excel"
    Exit Function
  
 upfail:
    Resume continue
  
 exitfail:
    On Error Resume Next
    SysCmd acSysCmdRemoveMeter
    xlApp.Visible = True         
    Set xlWB = Nothing  
    Set xlApp = Nothing
    rst.close
    Set rst = Nothing
    DoCmd.Hourglass False
    exportClaimToExcel = False
       
End Function
 
Responding to JHB and returning to my original question; It should be apparent from the SQL coding posted that the output file includes the parameters Name1, 2 & 3 which are simply Column Headings and that Firstname, Surname, [Address 1],Postcode and Subdate are fields of the Table [Mail List].

I am aware that non-field column headings will generate an'Input Parameter Value' message. My quesstion from the outset has always been = is there a method whereby one can amend the coding to prevent initiation of this message, As stated I would have thought that there should be such a facility within the Property Sheet source definitions.

Regards,

jcbhydro
 

Users who are viewing this thread

Back
Top Bottom