Results 1 to 9 of 9
  1. #1
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    Blank Field returning #Error

    Hello All!



    I have some code that is below!

    Code:
    Public Function DegreeChecker(AGShrs As Integer, ASBAhrs As Integer, ASCJhrs As Integer, AAhrs As Integer) As String
    Dim Degree As String
    
    If ((AGShrs = 0) And (ASBAhrs = 0)) Then
    Degree = "ASBA"
    ElseIf ((AGShrs = 0) And (ASCJhrs = 0)) Then
    Degree = "ASCJ"
    ElseIf (AGShrs = 0) Then
    Degree = "AGS"
    ElseIf (AAhrs = 0) Then
    Degree = "AA"
    Else
    Degree = "Potential"
    End If
    DegreeChecker = Degree
    End Function
    The problem is, the information that is populating the query which is running this code may not be there. As in some of the fields, AA, AGS, ASBA, and ASCJ might be left blank. Unless these four fields are populated by something, it returns #Error instead of the specified number.

    My question is then this: Is there a way to say, If variable is blank, ignore and continue on to check if the next thing is 0, or if none are 0, state Potential.

    Also on a side note. The information in this query is to be exported out to excel to be used as a Mail Merge file. I don't know anything about mail merge so if someone who knows can point me towards a website or set of instructions for this.

    Thanks!

    Imintrouble

    (Im in trouble, your in trouble, We're all in trouble)

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Look into the Nz() function.

  3. #3
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    This sounds like it could work, but how would it work with my code? I tried to just add another elseif into there but that didn't seem to work.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    ((Nz(AGShrs,0) = 0) And (Nz(ASBAhrs,0) = 0))

  5. #5
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    Thanks I suppose, but where would I put this into the code that I already have? Would it just go into another Elseif? so that

    Elseif ((Nz(AGShrs,0) = 0) And (Nz(ASBAhrs,0) = 0)) Then
    Degree = "whatever"

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You would use the Nz() function any time you might encounter a Null.

  7. #7
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Use of NZ()

    I'm guessing that your function arguments are supplied from a query. If so, perhaps you should use NZ in the query e.g. AGSHrs:NZ([AGSHrs],0) for each of the fields.

  8. #8
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    well the way i have it now is that I've created a coded module which is called into the field i created in design mode for the query which displays whatever degree is most prominant, AGS = AA, AGS & AA < ASCJ, AGS & AA < ASBA. or if none have 0 in their field just display Potential.

  9. #9
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    My Database

    In order to help even more with this annoying problem, i have attached a the part of my database that we have been discussing. Now a little bit on what exactly is needed.

    First of all I only require assistance where the query is concerned, not the table, unless the root of this is in the table which I highley doubt.

    Next, the only parts of the query which is involved are the fields,

    Hrs to AGS, Hrs to AA, Hrs to ASBA, Hrs to ASCJ, and the Degree field.

    How this is supposed to work is by entering numbers into those first four fields, you get an answer in the Degree field. However most of the time the information which will be populating these four fields will be blank. So there are two ways to do this, although I dont know the specifics.

    1. make it to where if their is a blank datafield, to instead of doing some fancy code work, simply make it N/A instead, this way their will be no null values to work with.

    2. Make it so that the code ignores the blank datafield to get an answer in the Degree field.


    Thanks! Hope this helps.

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

Similar Threads

  1. Recordset returning blank value
    By Mohamed in forum Access
    Replies: 1
    Last Post: 10-24-2011, 09:31 AM
  2. How to get pass the error I get when a field is blank
    By beanhead0321 in forum Programming
    Replies: 12
    Last Post: 08-16-2011, 08:09 PM
  3. IIF Statement Returning #Error
    By DrDefpoints in forum Queries
    Replies: 6
    Last Post: 05-26-2011, 12:25 PM
  4. Replies: 4
    Last Post: 05-11-2011, 03:06 AM
  5. Returning only the last number in a field
    By stanley721 in forum Queries
    Replies: 6
    Last Post: 03-07-2011, 10:37 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