Results 1 to 8 of 8
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    How do I track down what's causing this "#Error"?

    I have a query that calls a Function. It works on most records but on a couple instead of what I expect I get the text "#Error". I have zero idea how to track down mysterious errors, and am hoping someone can tell me how to debug this.

    My query is:
    Code:
    SELECT ConstructName(FirstName, LastName, BandName) AS FullName FROM Artists
    ConstructName just puts the name together with proper punctuation (like "Bach; J.S.").



    Of over 600 names, 7 or 8 return #Error instead of the constructed name. I thought perhaps there were bad invisible characters from an import so I deleted and recreated one of the problem records and that didn't help.

    I did put a watch on one of the bad names and the name doesn't appear to ever enter the function at all. That is, if I create a "break on true" watch on last_name = "Bach" it gets triggered, but my "break on true" for one of the problem names, "Prokofiev", is never triggered.

    So how does one approach an issue like this?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Can you post a copy of your database? zip format

    Can you post a copy of the function?

    Do you have Nulls in your data, and if so, do you handle NULL values?

  3. #3
    Join Date
    Apr 2017
    Posts
    1,687
    Open your function in VBA editor;

    Set a marker (click on left border of VBA module window - a dot appears there) for 1st code row which is not declaring variables. Close VBA editor;

    Run the operation which calls the function for some name you have a problem with. Tha VBA editor is opened with running code stopped at marked row;

    Press F8 repeatedly to process the function code row-wise and find the code row where your problem happens.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,479
    Sounds like bad data in one of those fields or special characters?. Look at some that are failing and what is different then ones that work? Can you post the actual record (FirstName, LastName, BandName) that are causing the issue?

  5. #5
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    Yeah, I did that, but the problem name never showed up in the function at all! It's as though the function never gets called for certain names.

  6. #6
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    Actually, I think this is a null issue. As an experiment, I added text to the empty BandName field in the Prokofiev record and it worked. The strange thing is, 90% of the records have an empty BandName field and most work fine. So I guess that means that I have a handful of records that have a null in BandName and the rest are empty strings?

    Is there a way to allow me to call ConstructName without error even if I'm passing a null value? Or do I need to do something like an UPDATE query that looks for null values and changes them to an empty string or something?

    This is the function:
    Code:
    Public Function ConstructName(fFirst As String, lLast As String, bBand As String) As String
    
        ' make sure there are no spaces at the ends
        fFirst = Trim(fFirst)
        lLast = Trim(lLast)
        bBand = Trim(bBand)
        
        
        If (Len(fFirst & "") > 0) Then
            fFirst = "; " & fFirst
        End If
        
        If (Len(bBand & "") > 0) Then
            bBand = " - " & bBand
        End If
        
        ConstructName = lLast & fFirst & bBand
    
    
    End Function

  7. #7
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82
    To answer my own question, it seems if I declare the arguments as Variants the null issue goes away. Thanks all.

  8. #8
    Join Date
    Apr 2017
    Posts
    1,687
    Quote Originally Posted by cherold View Post
    To answer my own question, it seems if I declare the arguments as Variants the null issue goes away. Thanks all.
    When this was the reason, using Nz() when calling the function would help too
    =ConstructName([FirstName], [LastName], Nz([Band],"")

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

Similar Threads

  1. Replies: 2
    Last Post: 07-14-2014, 10:34 AM
  2. Suppress "Error" message following "Cancel = True"
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-23-2014, 05:40 PM
  3. Replies: 6
    Last Post: 06-17-2013, 10:43 PM
  4. table field name "Year" causing Argument Not Optional
    By JosmithTwo in forum Programming
    Replies: 2
    Last Post: 09-26-2012, 08:01 PM
  5. StrComp causing "Invalid use of Null" error
    By sephiroth2906 in forum Programming
    Replies: 5
    Last Post: 09-15-2011, 07:06 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