+ Reply to Thread
Results 1 to 9 of 9

Open the recordset in access and use table name in dmax statement

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Open the recordset in access and use table name in dmax statement

    Hi folks

    I have developed a project in access as a backend and excel as a frontend so all the coding is in excel/vba.
    I am writing the following function but becvause I have to refer a table in access database , I need to open the recordset and use that table name in the dmax statement. Please see the code below:

    Please Login or Register  to view this content.
    I have a problem in code in red colour as tblbatchdetails is a table in access so how can we connect the frontend to this table. If I keed the access database opened while running the userform then it works fine but if the access database is closed and we try to tun the userform then it gives reserved error 2950 in dmax statement.

    Thanks for any help.

    Aman

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Open the recordset in access and use table name in dmax statement

    What is the point of the recordset if you do that? Why not include a WHERE statement in the SQL rather than just opening the table and select the Max value? In other wordds, something like:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Open the recordset in access and use table name in dmax statement

    Thanks for your reply. But I am getting runtime error 3265 "Item cannot be found in the collection corresponding to the requested name or ordinal" in the red line.
    Please Login or Register  to view this content.
    Can you please how to store the max finish time in a variable so that we can find out the elapsed time.

    Thanks
    Aman
    Last edited by aman1234; 05-10-2010 at 06:05 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Open the recordset in access and use table name in dmax statement

    Your field is probably called MaxOfFinishTime or something similar. You can alias it in the SQL string or use Fields(0) since it's the only field in the recordset.

  5. #5
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Open the recordset in access and use table name in dmax statement

    Many thanks for your reply. The code works fine when there are few records in the table and if the table is empty then in gives me an error "Invalid use of null"
    Please Login or Register  to view this content.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Open the recordset in access and use table name in dmax statement

    Check to see if records were returned:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Open the recordset in access and use table name in dmax statement

    Again it gives runtime error 94, "Invalid use of null" at

    dtmLower = rs.Fields(0)

    Thanks

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Open the recordset in access and use table name in dmax statement

    Oh, so you are actually getting a null field:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Open the recordset in access and use table name in dmax statement

    It worked gr8. Thanks a lot 4 your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1