custom nav buttons: no current record error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AccessIdiot
    Contributor
    • Feb 2007
    • 493

    custom nav buttons: no current record error?

    Please see attached screen shot. As you can see I have a main form (DPR_Main) with a subform (DPR_Survey). Within the subform is another subform (DPR_Resources) .

    I am using the following code I grabbed off the interwebs for the unbound textbox (called txtRecordNo) that acts as a record count:

    Code:
    Private Sub Form_Current()
    Dim rst As DAO.Recordset
        Dim lngCount As Long
        Set rst = Me.RecordsetClone
        With rst
            .MoveFirst
            .MoveLast
            lngCount = .RecordCount
        End With
    Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
    End Sub
    I have this on all three forms.

    For the three nav buttons I have the following code (again on all three forms):
    Code:
    Public Sub Next_Record()
    On Error GoTo Err_Next_Record
    
    With Recordset
      If .AbsolutePosition = .RecordCount - 1 Then
    'you are on the last record
            DoCmd.GoToRecord , , acFirst
      Else
    'you are on some other record
            DoCmd.GoToRecord , , acNext
      End If
    End With
    
    Exit_Next_Record:
        Exit Sub
    
    Err_Next_Record:
        MsgBox Err.Description
        Resume Exit_Next_Record
    End Sub
    -------------------------------
    Private Sub cmdAdd_Click()
        DoCmd.GoToRecord , , acNewRec
    End Sub
    
    Private Sub cmdNext_Click()
        Call Next_Record
    End Sub
    ------------------------------
    Private Sub cmdPrevious_Click()
    If Me.CurrentRecord > 1 Then
        DoCmd.GoToRecord , , acPrevious
    Else
        MsgBox "You are at the first record!", vbOKOnly, "Warning!"
    End If
    End Sub
    The next buttons work great on the Cultural Resources section and the DPR (main) section. On the Survey section I get an error that says "Run-time error '3201': No current record." When I debug it highlights the .MoveFirst or sometimes the.MoveLast part of the first code section posted above.

    The Add New button works only on the Cultural Resources section. The Previous button works fine.

    What am I doing wrong? I mean, besides trying to hack together code I don't fully understand that is.

    I am using MS2007 but saving as an 03 mdb, as that will be what our field crews will be running.
    Attached Files
  • AccessIdiot
    Contributor
    • Feb 2007
    • 493

    #2
    Never mind, I'm an idiot. Apparently I just needed
    Code:
    If rst.RecordCount <> 0 Then
    in the Form_Current

    Comment

    • Mariostg
      Contributor
      • Sep 2010
      • 332

      #3
      Did you run with a breakpoint to follow a step by step execution to find out where the error occurs?
      I have a strange feeling that lngCount = .RecordCount might return -1, unless you specify the option adOpenStatic (At least in Access 2003).
      Last edited by Mariostg; Sep 22 '10, 06:07 PM. Reason: OK Never mind my reply then...

      Comment

      • AccessIdiot
        Contributor
        • Feb 2007
        • 493

        #4
        Thanks for the reply - what I did seems to work but if it barks at me again I'll hit you up for a further explanation of your suggestion. :-)

        Comment

        Working...