A 2013 Invaid use of null Error 94

Dick7Access

Dick S
Local time
Today, 17:58
Joined
Jun 9, 2009
Messages
4,325
The following code works fine until it gets to last record, then it give me Error # 94 Invalid use of null. I have searched all of my code and null is not in the code.
Code:
'--------------------------------------------------------
' Goes to next record
'---------------------------------------------------------

Private Sub cmdNext_Click()

On Error GoTo err_handler
 
'   DoCmd.GoToControl (txtNameL)
  '  DoCmd.GoToRecord , , acNext
   DoCmd.GoToRecord acForm, "frmMain", acNext
    DoCmd.GoToControl "txtNameL"
    
Call CombFandS     'combines husband and wife over picture


cmdNext_Exit:
Exit Sub
 
err_handler:
If Err.Number = 2105 Then
   MsgBox "You have already reached the Last person.", vbApplicationModal, "Remember God does Knee Mail"
Else
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
   Resume cmdNext_Exit

End Sub
 
What line causes the error? Also, you have a function call in there. Are you sure the error doesn't occur in the sub or function "CombFandS?" What does that routine do, and does it handle it's own errors or does it raise them to the current routine?
 
What line causes the error? Also, you have a function call in there. Are you sure the error doesn't occur in the sub or function "CombFandS?" What does that routine do, and does it handle it's own errors or does it raise them to the current routine?

The function combines the husbands first name and the wife's first name over there picture. No, there is no error trapping in the function I didn't think I needed one
 
What line causes the error? Also, you have a function call in there. Are you sure the error doesn't occur in the sub or function "CombFandS?" What does that routine do, and does it handle it's own errors or does it raise them to the current routine?

After reading your post it made me take a second look at the code.. I moved the call before the "DoCmd.GoToRecord". It not only fixed the null error, but I was wondering why the image was slow in showing up and that fixed that also Thanks
 
Does anybody here see what might be causing a error when it gets to the last record. Actually it is not the last record, but in the blank record that is always at the bottom of a db. I think I am getting the picture. The last line is null and the function is trying to put two names together that are not there. How do I need to change the function?
Code:
Function CombFandS()
Dim strCombN As String
' strCombN = Me.txtNameF & " and " & Me.txtSpouce  ' first try procuced "and" when a single person was in  record
 strCombN = Me.txtNameF & (" and " + Me.txtSpouce)  'combines husband and wife over picture
 combName = strCombN
End Function
 
Does anybody here see what might be causing a error when it gets to the last record. Actually it is not the last record, but in the blank record that is always at the bottom of a db. I think I am getting the picture. The last line is null and the function is trying to put two names together that are not there. How do I need to change the function?
Code:
Function CombFandS()
Dim strCombN As String
' strCombN = Me.txtNameF & " and " & Me.txtSpouce  ' first try procuced "and" when a single person was in  record
 strCombN = Me.txtNameF & (" and " + Me.txtSpouce)  'combines husband and wife over picture
 combName = strCombN
End Function

Dick7Access,

Have you tried Nz()? I am sure I am not saying anything you do not know, but in my experience, the expressions Me.txtNameF & " and " & Me.txtSpouce and Me.txtNameF & (" and " + Me.txtSpouce) do not always product the same results. The deviations most often lie in the existence of Null Values.


Try one of the following and see if it makes any difference:
  1. strCombN = Nz(Me.txtNameF, "") & " and " & Nz(Me.txtSpouce, "")
  2. strCombN = Nz(Me.txtNameF, "") & (" and " + Nz(Me.txtSpouce), "")
Note that in each of the cases, the ,"" part is optional, and will be the default for a String. I added it to show the complete Syntax.

I believe that at least one of the above may be what you are looking for, although they should produce the same result.

-- Rookie
 
Dick7Access,t.

-- Rookie
(Did I know about nz) yes and no . One time someone on the forum showed me how to use it but I forgot. I didn't even remember it existed. I have a db that I call "How to" that I put info about access, win, excel, word, just about everything. The hard part is remembering to look there. When I get off here I will se if I entered it. If not I will have your snippet I can enter, thanks.
Dick S.
 
(Did I know about nz) yes and no . One time someone on the forum showed me how to use it but I forgot. I didn't even remember it existed. I have a db that I call "How to" that I put info about access, win, excel, word, just about everything. The hard part is remembering to look there. When I get off here I will se if I entered it. If not I will have your snippet I can enter, thanks.
Dick S.

It is always good to know that I can assist a fellow traveler. Thanks for letting us know what worked for you.

-- Rookie
 
It is always good to know that I can assist a fellow traveler. Thanks for letting us know what worked for you.

-- Rookie

Code:
strCombN = Nz(Me.txtNameF[B][COLOR=red], ""[/COLOR][/B]) & (" and " + Nz(Me.txtSpouce)[COLOR=red][B], ""[/B][/COLOR])
gave me a syntax error
 
I'd expect it to be . . .
Code:
Nz(Me.txtNameF, "") & " and " + Me.txtSpouce
. . . so if txtSpouse is null then the + " and " fails too and doesn't appear
 
If you are going to use Nz() on both names, why wouldn't you just do this . . .
Code:
strCombN = Me.txtNameF & " and " & Me.txtSpouce
The output will always be the same as this . . .
Code:
strCombN = Nz(Me.txtNameF, "") & (" and " + Nz(Me.txtSpouce, ""))
. . . and it's simpler to understand.
 
If you are going to use Nz() on both names, why wouldn't you just do this . . .
Code:
strCombN = Me.txtNameF & " and " & Me.txtSpouce
The output will always be the same as this . . .
Code:
strCombN = Nz(Me.txtNameF, "") & (" and " + Nz(Me.txtSpouce, ""))
. . . and it's simpler to understand.


If you will read my first post it says when I got to the last record it gave error # 94 invalid use of null
 

Users who are viewing this thread

Back
Top Bottom