Results 1 to 5 of 5
  1. #1
    Jedat is offline Novice
    Windows XP Access 2000
    Join Date
    Mar 2011
    Posts
    2

    Question Query export problems

    Hi all,

    I've got a db that has been given me to develop queries for to fulfill requests for Management Information.



    I have set some queries up and have them set to export into an excel sheet, so far so good. However 10 of these queries need to be run daily and then exported. If i go into them individually and change the date criteria, the correct data is then exported into excel.

    To make this process easier for the end user i have amended the date criteria field in the query to read [forms]![formname]![startdate] this takes the date from an unbound text box on the form.

    I have added a command button to the form with the following code behind to run the queries

    Code:
    Start Code
    
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qryFirstQuery"
    DoCmd.OpenQuery "qrySecondQuery"
    DoCmd.OpenQuery "qryThirdQuery"
    DoCmd.OpenQuery "qryFourthQuery"
    DoCmd.OpenQuery "qryFifthQuery"
    DoCmd.OpenQuery "qrySixthQuery"
    DoCmd.OpenQuery "qrySeventhQuery"
    DoCmd.OpenQuery "qryEighthQuery"
    DoCmd.OpenQuery "qryNinthQuery"
    DoCmd.SetWarnings True
    
    ''End Code
    This works and everything is fine, however if i then open the excel spreadsheet the exported queries all report a nil total as if they are not taking the date through.

    Has anyone any ideas how i can do this?

  2. #2
    KathyL is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    94
    Quote Originally Posted by Jedat View Post
    Hi all,

    I've got a db that has been given me to develop queries for to fulfill requests for Management Information.

    I have set some queries up and have them set to export into an excel sheet, so far so good. However 10 of these queries need to be run daily and then exported. If i go into them individually and change the date criteria, the correct data is then exported into excel.

    To make this process easier for the end user i have amended the date criteria field in the query to read [forms]![formname]![startdate] this takes the date from an unbound text box on the form.

    I have added a command button to the form with the following code behind to run the queries

    Code:
    Start Code
    
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qryFirstQuery"
    DoCmd.OpenQuery "qrySecondQuery"
    DoCmd.OpenQuery "qryThirdQuery"
    DoCmd.OpenQuery "qryFourthQuery"
    DoCmd.OpenQuery "qryFifthQuery"
    DoCmd.OpenQuery "qrySixthQuery"
    DoCmd.OpenQuery "qrySeventhQuery"
    DoCmd.OpenQuery "qryEighthQuery"
    DoCmd.OpenQuery "qryNinthQuery"
    DoCmd.SetWarnings True
    
    ''End Code
    This works and everything is fine, however if i then open the excel spreadsheet the exported queries all report a nil total as if they are not taking the date through.

    Has anyone any ideas how i can do this?
    If you have the form loaded, and the date on it.... and then you just run one of the queries from the object list... does it give you results for the one query? It should. If not, perhaps an error in the query.

  3. #3
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Sometimes it has to do with the criteria and the wrong form/field name. I'd run each one manually as KathyL suggested.

    You can also check that startdate is formatted as a date field on the form and make sure your criteria is under a date field type column in the query (if it is actually based on a date field).

    I'd also test to see if startdate is null before executing the queries since date type fields in queries sometimes don't work well with null values.

  4. #4
    Jedat is offline Novice
    Windows XP Access 2000
    Join Date
    Mar 2011
    Posts
    2
    Thanks for the replies, the query does return results when run individually with the form open or when run through the form itself. The problem occurs when i try to export the query into excel.

    As soon as i export the queries the figures revert to 0, i think it is more to do with my excel than access to be honest, i will be investigating that route as well with my IT bods, but any other suggestions gladly welcomed.

  5. #5
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Are you sure it's not a Yes/No field? These would export as 0 or -1. Otherwise I'd try exporting as a csv file to see what the value is.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export query to CSV
    By daniel.preda in forum Import/Export Data
    Replies: 3
    Last Post: 12-30-2010, 08:52 AM
  2. Problems with IIF in query
    By ducecoop in forum Access
    Replies: 1
    Last Post: 11-15-2010, 10:29 AM
  3. Problems with export
    By bbshriver in forum Import/Export Data
    Replies: 8
    Last Post: 10-30-2010, 06:16 PM
  4. SQL Query Problems
    By slaterino in forum Queries
    Replies: 2
    Last Post: 08-26-2010, 09:06 AM
  5. Query problems
    By geoffishere in forum Forms
    Replies: 1
    Last Post: 02-09-2010, 12:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums