Results 1 to 5 of 5
  1. #1
    Wayne311 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    91

    Invalid use of Null

    I have a form where the user could invoke a procedure out of order and cause an error. The first field is null until the next field has any data entered at which point the first field is populated with a number. I am trying to stop the error and re-direct the user to the proper field. Any suggestions?



    Thanks
    Wayne

    Private Sub Command10_Click()
    If (Forms(Me.Parent.Name).Controls("RcptCRDistrict Subform1").Form!RcptNumber) = Null Then
    MsgBox ("Enter Last Name") End If
    Me.Text8 = DSum("Charge", "RcptCRDistrict", "[RcptNumber] = " & Forms(Me.Parent.Name).Controls("RcptCRDistrict Subform1").Form!RcptNumber)
    Me.Refresh
    End Sub

  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,518
    Nothing is ever equal to Null. Try

    If IsNull(...) Then

    You'll also want an Exit Sub in there to stop the code from trying the formula.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    SteveF is offline Generally AccessAble
    Windows XP Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Fourth Corner
    Posts
    123
    Quote Originally Posted by Wayne311 View Post
    I have a form where the user could invoke a procedure out of order and cause an error. The first field is null until the next field has any data entered at which point the first field is populated with a number. I am trying to stop the error and re-direct the user to the proper field. Any suggestions?

    Thanks
    Wayne

    Private Sub Command10_Click()
    If (Forms(Me.Parent.Name).Controls("RcptCRDistrict Subform1").Form!RcptNumber) = Null Then
    MsgBox ("Enter Last Name") End If
    Me.Text8 = DSum("Charge", "RcptCRDistrict", "[RcptNumber] = " & Forms(Me.Parent.Name).Controls("RcptCRDistrict Subform1").Form!RcptNumber)
    Me.Refresh
    End Sub
    I think the problem is with the If statement -- the "= Null" is what is giving you the error.

    Try this instead:
    If IsNull(<NameOfControl>) = True Then

    In the True section of the If/Then, you should also explicitly re-direct the user to the last name control, like this:
    <LastNameControl>.SetFocus

    and exit the Proc (Exit Sub) if nothing else should happen until the last name is entered.

    So the section would look like this:
    If IsNull(Forms(Me.Parent.Name).Controls("RcptCRDistr ict Subform1").Form!RcptNumber) = True Then
    MsgBox ("Enter Last Name")
    <LastNameControl>.SetFocus
    Exit Sub
    End If

    Steve

  4. #4
    Wayne311 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    91
    Thank you for the replys. It works with the following changes (for those who care).

    Thread Solved!
    Wayne

    Private Sub Command10_Click()
    If IsNull(Forms(Me.Parent.Name).Controls("RcptCRDistr ict Subform1").Form!RcptNumber) = True Then
    MsgBox ("Enter Last Name")
    Forms(Me.Parent.Name)!CarrierLName.SetFocus
    Exit Sub
    End If
    Me.Text8 = DSum("Charge", "RcptCRDistrict", "[RcptNumber] = " & Forms(Me.Parent.Name).Controls("RcptCRDistrict Subform1").Form!RcptNumber)
    Me.Refresh
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    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. invalid procedure call
    By johnmerlino in forum Access
    Replies: 5
    Last Post: 12-13-2010, 10:12 AM
  2. Invalid Use of Null!?!
    By Kipster1203 in forum Access
    Replies: 4
    Last Post: 05-13-2010, 06:09 AM
  3. List box value to variable - invalid use of null?
    By Orabidoo in forum Programming
    Replies: 2
    Last Post: 05-07-2009, 11:06 AM
  4. Replies: 0
    Last Post: 11-17-2006, 09:38 AM
  5. Invalid Operation
    By ScottG in forum Forms
    Replies: 0
    Last Post: 11-14-2006, 02:05 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