Results 1 to 9 of 9
  1. #1
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47

    creating recordset based on query

    im trying to open a recordset from a table based on a query statement. I have attached the code up to the point where I get a "Run-time error '424' : Object Required". Can anyone see the problem in the code?

    Dim query As String
    Dim rs1 As DAO.Recordset
    Dim rs2 As DAO.Recordset


    Set rs1 = CurrentDb.OpenRecordset("EmployeeData")
    Do Until rs1.EOF 'D0 runs the code below until it reaches the end of the recordset
    'creates a new recordset w/ records from ResourceAllocation table
    'where HRID(RA) = HRID(ED) and project lies within the month
    query = "SELECT ResourceAllocation.* FROM ResourceAllocation WHERE (((ResourceAllocation.[HRID]) = rs1.Fields(""HRID"") AND ((ResourceAllocation.[Resource Start Date])<#1/31/2012#) AND ((ResourceAllocation.[Resource End Date])>#1/1/2012#))"


    Set rs2 = CurentDb.OpenRecordset("query")

    Tables in the database are EmployeeData and ResourceAllocation. HRID is a field set in both tables and the Resource Start Date and Resource End Date fields are both dates we are using for comparisons.

  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,652
    You have to concatenate the recordset value into the string, like:

    "...WHERE (((ResourceAllocation.[HRID]) = " & rs1.Fields("HRID") & " AND..."

    Which assumes it's numeric.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Still getting the same error. when i debug, i highlights this line:

    Set rs2 = CurentDb.OpenRecordset("query")

    i think the query itself is working, just doesnt like me to use the string as the parameter...

  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,652
    This should help us figure out what's wrong with the string:

    http://www.baldyweb.com/ImmediateWindow.htm

    If you don't spot the problem, post the SQL here. Oh, if that's a copy/paste, you've misspelled "Current".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    ok now i feel like an idiot. it cleared up the 424 code but now the same line is throwing a 3464 run-time error. says "data type mismatch in criteria expression. Do i need put query in quotations? So currentdb.openrecordset("query")

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No because it's a variable (you'd put an SQL string in quotes). I suspect HRID is a text data type, so this (note the single quotes added in red):


    "...WHERE (((ResourceAllocation.[HRID]) = '" & rs1.Fields("HRID") & "' AND..."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Yes it is, let me try it

  8. #8
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    looks like that did the trick. Now everytime i run the code the DB stops responding. probably from the large amount of computing it has to do. Ill let you know if i have any more questions. Thanks for the help

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help. Don't know what you're trying to do, but loops can certainly be slow.
    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. Replies: 4
    Last Post: 08-23-2012, 12:28 AM
  2. Creating an updatable query recordset using Access 2010
    By Bill McCoy in forum Programming
    Replies: 1
    Last Post: 04-17-2012, 09:36 AM
  3. Replies: 10
    Last Post: 03-02-2012, 11:06 AM
  4. MessageBox Based on Recordset Count
    By Two Gun in forum Forms
    Replies: 3
    Last Post: 12-25-2011, 07:54 AM
  5. Replies: 0
    Last Post: 08-31-2009, 10:50 AM

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