Results 1 to 10 of 10
  1. #1
    prabha_friend is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Location
    Chennai
    Posts
    5

    Exclamation Getrows method not working


    Sub Test()
    Dim myrset As Recordset
    Dim temp As Variant
    Set myrset = CurrentDb.OpenRecordset("SELECT * FROM Holidays;")
    temp = myrset.GetRows(myrset.RecordCount)
    MsgBox UBound(temp)
    End Sub

    I also tried with including the patrol (myrset.movelast and myrset.movefirst) before accessing the recordcount. Still its giving the UBound 0. But Recordcount is 2.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't use GetRows but...

    What is it you are trying to accomplish with GetRows? How many records are in table Holidays? How, exactly, do you know it is not working? I do not see any code example of you using Ubound.

  3. #3
    prabha_friend is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Location
    Chennai
    Posts
    5

    To Use the Networkdays function in Access...

    Quote Originally Posted by ItsMe View Post
    I don't use GetRows but...

    What is it you are trying to accomplish with GetRows? How many records are in table Holidays? How, exactly, do you know it is not working? I do not see any code example of you using Ubound.
    Hey You. Actually I need that recordset to be converted into an array, Because I want to use the Networkdays function in the excel application using the excel.application.worksheetfunction.NetworkDays(Arg1, Arg2, Arg3)

    Note:
    Arg3 - Optional Variant Holidays - an optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. The list can be either a range of cells that contains the dates or an array constant (array: Used to build single formulas that produce multiple results or that operate on a group of arguments that are arranged in rows and columns. An array range shares a common formula; an array constant is a group of constants used as an argument.) of the serial numbers that represent the dates.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    That sounds pretty cool. How do you know it is not working? Maybe it is a memory issue if there are many records in your table. Can you show how you tested it using Ubound?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Not sure if this is what you are looking for...


    Code:
    Dim intRecords As Integer
    Dim inRows As Integer
    Dim myrset As DAO.Recordset
     Dim temp As Variant
     Set myrset = CurrentDb.OpenRecordset("SELECT * FROM Table1;")
    myrset.MoveLast
    myrset.MoveFirst
    temp = myrset.GetRows(myrset.RecordCount)
    ' MsgBox UBound(temp)
    intRecords = UBound(temp, 2) + 1
    
    MsgBox intRecords

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Last edited by orange; 07-31-2014 at 07:38 AM.

  7. #7
    prabha_friend is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Location
    Chennai
    Posts
    5

    Question How to pass only a single dimension of an array?

    Hi all,
    Thank you for your answers. Now the getrows is working fine at my end. Now I have a different problem at hand:

    Sub Test2()
    Dim myrset As Recordset
    Set myrset = CurrentDb.OpenRecordset("SELECT * FROM Holidays;")
    myrset.MoveLast
    myrset.MoveFirst
    MsgBox myrset.RecordCount
    MsgBox excel.Application.WorksheetFunction.Networkdays(#8/1/2014#, #8/31/2014#, Array(#8/15/2014#, #8/29/2014#))
    MsgBox excel.Application.WorksheetFunction.Networkdays(#8/1/2014#, #8/31/2014#, excel.Application.WorksheetFunction.Index(myrset.G etRows(myrset.RecordCount), 0, 1))
    End Sub

    Recordcount is coming fine
    Manual Array is also giving the right result
    But the Index method is giving the wrong value. Why?

    (Holidays table is just having the values in the array only ie. #08/15/2014# and #08/29/2014#)

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I do not understand the purpose of
    myrset.GetRows(myrset.RecordCount)

    why not just
    myrset.RecordCount ???

    I am not an expert in Excel stuff but, the way I see it (and I am not really interested in trying to understand it), the Index method requires a Multidimensional Array as its parameter. So you should pass the values from your DAO Recordset to the Index parameters. Determine if the Index parameters are 0 based index or 1 Based.

    Something like ... where intCount is the field index you are after
    WorksheetFunction.Index(myrset.RecordCount, myrset.AbsolutePosition + 1, intCount + 1)
    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    As far as I can tell, GetRows is simply a helper method to get the row count, just like .RecordCount is a helper method to get the row count.
    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

  9. #9
    prabha_friend is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2014
    Location
    Chennai
    Posts
    5
    Hey You. No. RecordCount give only the count of records but getrows give the records itself in an array.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK........

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

Similar Threads

  1. Replies: 4
    Last Post: 02-09-2013, 09:26 AM
  2. GetRows method problem
    By exhumed in forum Programming
    Replies: 3
    Last Post: 10-01-2012, 01:49 PM
  3. Replies: 5
    Last Post: 08-07-2012, 11:31 AM
  4. GetRows() returning one record only
    By ajetrumpet in forum Programming
    Replies: 3
    Last Post: 09-09-2010, 09:32 PM
  5. GetRows - Invalid Use of Nulls
    By Wannabe_Pro in forum Programming
    Replies: 3
    Last Post: 07-22-2009, 07:07 AM

Tags for this Thread

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