Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Error Detection
Kent Morstain 
    
3 years ago
This should be simple, but what is the syntax I can use to catch a blank field? I have tried variations of the StudentID = 0 and or trying to catch sTDJC being null, but it doesn't like the syntax or falls through to sTDCJ.

What I am trying to do is catch an empty TDCJ field so that unless it is not blank it never gets to the sTDCJ entry and forces the user to put a value in the TDCJ field.

Right now when TDCJ is blank I get an error, Invalid use of Null.


    StudentID = Nz(DLookup("StudentID", "StudentT", "TDCJ=""" & TDCJ & """"), 0)
  
    If StudentID > 0 Then
      ' TDJC Number found, Lookup Info
            TDCJ = DLookup("TDCJ", "StudentT", "StudentID=" & StudentID)
            MsgBox ("Student exist, verify TDCJ #, and Re-Enter")
            TDCJ = Null
            LastName = Null
            FirstName = Null
            DOB = Null
            Unit = Null
            Address = Null
            City = Null
            State = Null
            ZIP = Null
            TDCJ.SetFocus
      
   Else: StudentID = 0
      ' TDJC Number NOT found, add New Student Info
            sTDCJ = TDCJ
            sLastName = LastName
            sFirstName = FirstName
            sDOB = DOB
            sUnit = Unit
            sAddress = Address
            sCity = City
            sState = State
            sState = UCase(sState)
            sZIP = ZIP
          
            SQL = "INSERT INTO StudentT ( TDCJ, LastName, FirstName, DOB, UNIT, Address, City, State, ZIP ) " & _
                    "SELECT """ & sTDCJ & """, """ & sLastName & """, """ & sFirstName & """, """ & sDOB & """, """ & sUnit & """, """ & _
                    sAddress & """, """ & sCity & """, """ & sState & """, """ & sZIP & """"
            
            DoCmd.RunSQL SQL
          
        End If
        
    End Sub
Kent Morstain OP  @Reply  
    
3 years ago

Kevin Robertson  @Reply  
          
3 years ago
You need to wrap the DLookup  with the NZ function as you did for StudentID.

TDCJ = Nz(DLookup("TDCJ", "StudentT", "StudentID=" & StudentID),"")

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: 8/24/2026 9:28:18 AM. PLT: 1s