Results 1 to 4 of 4
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    A RecordSet based on a Union Queries

    I have 4 queries that build on each other qryTable1 reads Table1, qryTable2 reads Table2, qryUnion combines the two and qry4 joins qryUnion with 3 other tables and appends it to tblData. I can run the queries as they are and get the results I need, but I would like to move part of the process into a DAO recordset based on the SQL in qry4 and I've built a script that does that, almost. When I try to open the recordset I get runtime error 3061 Too few parameters. Expected 4.

    Well there are 4 parameters, text boxes on a form, and I've declared them specifically everywhere I use them qryTable1, qryTable2, and in the SQL script in my procedure. I've even replaces the parameters with variables in the script. I know the SQL is valid because I've copies it from the Immediate window and plugged it into a query. I'm nearly convinced this can't be done, but before I give up I thought I would toss it out there. Here's how I've declared the parameters in the script.



    Code:
       SQL1 = "PARAMETERS [Forms]![frm_DowntimeReasons]![txt_FromDate] DateTime, "  & _
    [Forms]![frm_DowntimeReasons]![txt_TillDate] DateTime, " & _
    "[Forms]![frm_DowntimeReasons]![txt_FromTime] DateTime,  "  & _
    [Forms]![frm_DowntimeReasons]![txt_tillTime] DateTime; "
    I've also pasted this SQL into the first two queries.

    Code:
    PARAMETERS Forms!frm_DowntimeReasons![txt_FromDate] DateTime, Forms!frm_DowntimeReasons![txt_FromTime] DateTime, 
    Forms!frm_DowntimeReasons![txt_TillDate] DateTime, Forms!frm_DowntimeReasons![txt_TillTime] DateTime;
    Everything runs perfectly except when I try to open the recordset.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, you're running into this:

    http://support.microsoft.com/default...b;en-us;209203

    An alternative that often works is wrapping each form reference in the query in the Eval() function. If you're building the SQL in code (I can't tell for sure), you would concatenate the form reference in, along the lines of:

    SQL1 = "...WHERE DateField Between #" & Forms!frm_DowntimeReasons![txt_FromDate] & "# And #" & Forms![frm_DowntimeReasons]![txt_TillDate] & "#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    I (re)built this who thing in code to mimic an existing (functioning) query. I've hit this from every angle I can think of. My only conclusion from this is that some things are just meant not to be, or just not worth the effort. I'm going to let Access do what it does best and move on.

    Thanks anyway,

    Paul
    Last edited by Paul H; 05-31-2012 at 01:53 PM. Reason: typo

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, though I think Access could have done it just fine.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. One filter for 3 Queries in Union Query
    By rlsublime in forum Access
    Replies: 3
    Last Post: 03-20-2012, 04:01 PM
  2. Union Queries
    By tarhim47 in forum Queries
    Replies: 6
    Last Post: 05-26-2011, 12:20 PM
  3. Replies: 0
    Last Post: 03-14-2011, 08:38 AM
  4. Union Queries when Splitting Database
    By jaypoppin in forum Queries
    Replies: 3
    Last Post: 03-04-2011, 06:06 PM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 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