Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Error on no value
Masih Ostad Novin 
     
3 years ago
Hi. I created a field that is flashing and it works nice. The problem is when I have nothing in my table, the autonumber =new. Then I get this error. See below. My code is:

On timer even

If IsNull(Sum) Or 0 Then Exit Sub
        If Sum > 400 Then
        If Sum.BackColor = vbWhite Then
            Sum.BackColor = vbRed
            Sum.ForeColor = vbWhite
    Else
        Sum.BackColor = vbWhite
        Sum.ForeColor = vbBlack
        End If
    End If

I tried with If IsNull(Sum) Or 0 Then Exit Sub but it doesn't help. I must have a value in my table.
Any suggestions?
Best, Masih

Masih Ostad Novin OP  @Reply  
     
3 years ago

Kevin Robertson  @Reply  
          
3 years ago
The first line should be:
If IsNull(FieldName) Or FieldName = 0 Then Exit Sub

Replace FieldName with the name of your field.

Don't use Sum as a field name as it is a reserved word. It is the name of a function.
Masih Ostad Novin OP  @Reply  
     
3 years ago
The error message still pops up.
Masih Ostad Novin OP  @Reply  
     
3 years ago

Kevin Yip  @Reply  
     
3 years ago
When your form has no record, all your fields have no value.  When you reference one of your fields with Me.Field1, you will also get the "expression as no value" error.  When you try to sum a field with "no value," your sum field will, of course, also has no value, and that's why you got this error.  "No value" doesn't mean null, so IsNull() doesn't catch it. The workaround for this is to first check if your form has any record, such as with the DCount() function, or with the Form.Recordset.Recordcount property.
Masih Ostad Novin OP  @Reply  
     
3 years ago
I don't think that would be the problem since the form gets its value from a query.
Kevin Robertson  @Reply  
          
3 years ago
Is this a calculated field?

Please post some screenshots of both your Form and your Query.
Masih Ostad Novin OP  @Reply  
     
3 years ago
Yes.
Masih Ostad Novin OP  @Reply  
     
3 years ago

Masih Ostad Novin OP  @Reply  
     
3 years ago

Masih Ostad Novin OP  @Reply  
     
3 years ago

Masih Ostad Novin OP  @Reply  
     
3 years ago
The second query is based on the first one. Everything works fine but the error message when the table has no value in it.
Kevin Robertson  @Reply  
          
3 years ago
Does this work for you?

    Dim myCount As Long
    
    myCount = DCount("*", "OrderSumQ")
    If myCount = 0 Then Exit Sub
    
    If IsNull(OrderSum) Or OrderSum = 0 Then Exit Sub
    
    If OrderSum > 400 Then
        If OrderSum.BackColor = vbWhite Then
            OrderSum.BackColor = vbRed
            OrderSum.ForeColor = vbWhite
        Else
            OrderSum.BackColor = vbWhite
            OrderSum.ForeColor = vbBlack
        End If
    End If
Kevin Yip  @Reply  
     
3 years ago
Hi Masih, whether it comes from a query or a form, it will still give the "expression has no value" error.  If there is no record to be summed, then the sum is not zero, not null, but "no value".  In Kevin's code above, the conditions IsNull(OrderSum) or OrderSum=0 will always be false because OrderSum will never be null or zero when there is no record to sum.  You can easily prove this with the immediate window.  Set a break on point that line.  When the execution pauses there, type:

    ?OrderSum

in the immediate window.  You will get the "expression has no value" error just like that.
Masih Ostad Novin OP  @Reply  
     
3 years ago
Thanks. Great. It seems that Kevins code worked just fine.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 2:05:54 AM. PLT: 1s