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!

Custom Navigation 3

Status
Not open for further replies.

wdverner

Technical User
Mar 10, 2005
160
GB
Hi guys,
Just a quick one..

i have my own navigation buttons on a form- the user cant add records to a form, what i want is when the user clicks the Next button and if there are no more records to display then it shows a custom error message?

Cheers
 
I guess you do it with a Recordset.
Either test the BOF and EOF properties after the MoveNext (MovePrevious) calls or the AbsolutePosition against RecordCount (or 0) before the calls.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This is what I call a quick and dirty solution that requires very little coding. Basically you create a dao recordset object and set it to equal the form's recordset. Below is a code snippet that works.

Code:
Dim objRec As DAO.Recordset

Private Sub Form_Load()

    Set objRec = Me.Recordset
    
End Sub

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

    
    objRec.MoveNext
    If objRec.EOF Then
        MsgBox "You have reached the end of the recordset", vbInformation
        Exit Sub
    End If
    
Exit_cmdNext_Click:
    Exit Sub

Err_cmdNext_Click:
    MsgBox Err.Description
    Resume Exit_cmdNext_Click
    
End Sub
Private Sub Form_Unload()

   Set objRec = Nothing

End Sub

 
If I understand your question, I think you simply have to replace the line

MsgBox Err.Description

in your sub with your own custom messagebox.

Depending on exactly what you're trying to do, you might also consider "wrapping" around from the last record back to the first record by replacing this same line with

DoCmd.GoToRecord , , acFirst.

You can also wrap in the other direction (when a user on the first record hits Previous) by using

DoCmd.GoToRecord , , acLast.

Hope this helps!

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
How are ya wdverner . . .

Try this:
Code:
[blue]   Dim rst As DAO.Recordset
   
   Set rst = Me.RecordsetClone
   
   [green]'Goto the same record on the form.[/green]
   rst.FindFirst "[[purple][b]PrimaryKeyName[/b][/purple]] = [red][b]'[/b][/red]" & Me![purple][b]PrimaryKeyName[/b][/purple] & "[red][b]'[/b][/red]"
   rst.MoveNext
   
   If rst.EOF Then
      MsgBox "Your Error Message Here!"
   Else
      DoCmd.RunCommand acCmdRecordsGoToNext
   End If
   
   Set rst = Nothing[/blue]
If the PrimaryKey is numeric, remove the single quotes [red]'[/red]

Calvin.gif
See Ya! . . . . . .
 
Some interesting suggestions here alredy, but here's even another approach (number of ways to skin a cat etc...) - try the .currentrecord property to determine whether moving to next/previous record is allowed.

[tt] ' moveprevious thingie
if me.currentrecord = 1 then
msgbox "alredy at the first ..."
else
docmd.gotorecord,,acprevious
end if


' movenext thingie
dim rs as dao recordset
set rs = me.recordsetclone
if rs.recordcount > 0 then
rs.movelast
if rs.recordcount = me.currentrecord then
msgbox "alredy at the last ..."
else
docmd.gotorecord,,acnext
end if
else
msgbox "ouch - are there any records at all ..."
end if
set rs = nothing[/tt]

- air code ...

You could probably use some coding similar to this, to toggle the enable properties of your custom navigation buttons, too ...

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top