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

    is this a valid statment


    Can someone look at the code below and see why im getting a run-time 424 error?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    I can't see any code in your post.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Dur....sorry about that. Here it is

    Set rs2 = CurentDb.OpenRecordset("SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName(0) = rs1(0) AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#")

    trying to create a recordset by using records from the ResourceAllocation table where the last name is = to a value i designate, and the values for the dates are in January.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    LastName(0) = rs1(0)
    Can you explain the bracketed number after LastName and what is rs1(0)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Sorry, that field is a combobox and i was trying to pull the value from column 0 so it should read ResourceAllocation.LastName.Column(0) . rs1(0) is the first field from the recordset.

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Try:
    Set rs2 = CurentDb.OpenRecordset("SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName(0) = rs1.("FieldName") AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Changed it to

    Set rs2 = CurentDb.OpenRecordset("SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName.Column(0) = rs1.HRID AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#")

    but still have the same error.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Did you try:
    Set rs2 = CurentDb.OpenRecordset("SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName.Column(0) = rs1.Fields("HRID") AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Yes and it made the line of code red. Doesnt like that change.

  10. #10
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    string within a string. try creating a string type variable and set it to
    "SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName.Column(0) = rs1.Fields(""HRID"") AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#"

    Then open the recordset on the string variable.

  11. #11
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    I changed the code to :

    query = "SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName.Column(0) = rs1.Fields(""HRID"") AND [Resource Start Date] < #1/31/2012# AND [Resource End Date] > #1/1/2012#"
    Set rs2 = CurentDb.OpenRecordset(query)

    but im still getting the error. This time however, the problem was in the line :
    Set rs2 = CurentDb.OpenRecordset(query)

    ideas?

  12. #12
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    is it even possible to open a recordset using a query with where conditions?

  13. #13
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I think the problem is with your trying to use a combobox in the sql in vba
    ResourceAllocation.LastName.Column(0)
    and possibly not setting the rs2 object somewhere

    If you are referring to a combobox, it will be on a form.
    If you want to include a form control in sql in vba, you need to "render'( my term) the form control's value.

    along these lines
    query = "SELECT * FROM ResourceAllocation WHERE ResourceAllocation.LastName = '" & Me.yourCombobox.value "' ......"


    But I think that rs1 is probably not set.


    You could try a debug.print query to see what the SQL is in Access' view.

    In any case please show all of the code.

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

Similar Threads

  1. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM
  2. Syntax Error on Update Statment
    By TinaCa in forum Programming
    Replies: 2
    Last Post: 09-14-2011, 05:53 PM
  3. Error message for criteria statment
    By macattack03 in forum Queries
    Replies: 1
    Last Post: 04-23-2011, 11:21 AM
  4. IF statment criteria??
    By cthai in forum Queries
    Replies: 1
    Last Post: 03-19-2011, 02:51 AM
  5. SQL statment structure
    By oss_ma in forum Programming
    Replies: 1
    Last Post: 05-13-2007, 02:08 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