Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invalid use of null

Status
Not open for further replies.

belovedcej

Programmer
Nov 16, 2005
358
0
0
US
The following code is activated when a user clicks on a button. It is supposed to go to the next record. If the next record is empty, I want Access to jump back to the previous record and issue a message indicated it is the end of the records.

This works fine until I get to the end of the record set. Then I get an "invalid use of Null" warning. Any ideas?



DoCmd.GoToRecord , , acNext

Dim strParty As Integer
strParty = Me.Party_Type_ID

If strParty < 1 Then
DoCmd.GoToRecord , , acPrevious
MsgBox "End of Record", vbOKOnly
End If
 
Hey beloved,

You have your DoCmd....acNext outside your IF statement. Try nesting inside the IF statement and see what it does for you.

ie:
If strParty < 1 Then
DoCmd.GoToRecord , , acPrevious
MsgBox "End of Record", vbOKOnly
else
DoCmd.GoToRecord,,acNext
End If

HTH,
Shane
 
You could also test the EOF property. Use a Do while not .eof loop perhaps.

Access makes all things possible. It even makes them intelligible
 
If you want to use that code, try this:

Code:
    DoCmd.GoToRecord , , acNext
    
    if isnull(Me.Party_Type_ID) then
        DoCmd.GoToRecord , , acPrevious
        MsgBox "End of Record", vbOKOnly
    End If

As long as that field is not left null when added, it should work. It probably would be a better idea to use eof, though.
 
Amigo - thanks for the thought. Turns out that won't work because the Party_ID is always greater than one until I get to the empty record.

I need to somehow tell it not to check the party ID until it gets to the new record.

Mikey, I'm trying to do the Loop as suggested, however, I've never worked with the end of record function before and I'm having problems. Could flesh out your suggestion a bit? Thanks!
 
Here's a thought.
Code:
DoCmd.GoToRecord , , acNext

if me.recordsetclone.eof then
    DoCmd.GoToRecord , , acPrevious
end if
It should work.
 
Ruel, that was perfect - either option works! Thanks!
 
belovedcej - see that Reuel got there before me. Are you fixed up? You can also use movefirst, movenext, movelast, etc commands instead of GoToRecord. And don't overlook .BOF - another useful attribute.

Access makes all things possible. It even makes them intelligible
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top