Results 1 to 8 of 8
  1. #1
    tarenja is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    15

    Iteration problem. Calling a function but crashes when eof reached

    I have a simple form that allows the user to loop through all records in a table.
    On each iteration there are calls to a function.


    The calls are being made from text boxes.
    It all works fine until I get to the end of the table when an empty set of values is passed to the function and then it crashes.
    I understand why it crashes but I'm don't know what approach to use to prevent it calling the function when the EOF is reached.
    Can I keep using the "standard" MS Access navigation buttons on the form or do I need to set up my own iteration controls and somehow test for end of file on each iteration?
    Any help would be greatly appreciated.

  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 should be able to modify your function to handle the empty values. Hard to be specific without seeing it, but likely you need to declare the input parameters as Variant and test them for Null in the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tarenja is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    15
    As soon as the eof if reached the function goes to the error handler.
    I have no idea of what to test for to trap the problem.

    Public Function getActivityNames(DelegateID As Variant, ActivityIDs As Variant) As Variant

    Dim strSql As String
    Dim strOut As String
    Dim Arrayids As Variant
    Dim i As Integer
    Dim ingLength As Integer
    Dim dbs As DAO.Database
    Dim rsB As DAO.Recordset
    Dim rsC As DAO.Recordset

    On Error GoTo Err_Handler

  4. #4
    tarenja is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    15
    Thank you. I tried:
    Debug.Print DelegateID, ActivityIDs
    DelegateID was null hence
    If DelegateID <> Null Then
    don't do anything

    and bingo.

  5. #5
    tarenja is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    15
    I just read that my solution isn't technically correct.
    I've now changed it to:
    If IsNull(DelegateID) Then Exit Function

  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
    So it's working now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    tarenja is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    15
    Yes thank you very much.
    You pointed me in the right direction to look for the solution.

  8. #8
    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 problem.
    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. Calling a Private Function from Another Form
    By MintChipMadness in forum Programming
    Replies: 1
    Last Post: 01-07-2013, 12:08 PM
  2. Calling a Function From A Form.
    By ksmith in forum Access
    Replies: 2
    Last Post: 06-07-2012, 02:23 PM
  3. Calling A Module Function To Open A Form
    By orcinus in forum Modules
    Replies: 3
    Last Post: 09-29-2010, 04:43 PM
  4. calling function
    By ManvinderKaur in forum Programming
    Replies: 3
    Last Post: 07-22-2010, 10:53 PM
  5. Calling a function and returning a value
    By 3dmgirl in forum Programming
    Replies: 0
    Last Post: 04-23-2007, 02:20 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