
Navigation Buttons - Not Allowing New Record Creation with Next Record
Just set the Form's AllowAdditions property to False.
Alternatively, if you still need the form to be able to allow record
additions, then you can put something like this (air code) in the "Next"
button you have created:
Dim rst As Recordset
Dim MaxRecords As Long
Set rst = Me.RecordsetClone
rst.MoveLast
MaxRecords = rst.RecordCount
rst.Close
Set rst = Nothing
If MaxRecords = Me.CurrentRecord then
Exit Sub 'We're on the last record, so do nothing
Else
DoCmd.GotoRecord , , acNext 'Go to the next record
End If
Quote:
> I have created the navigation buttons I need to go to next record,
> previous recourd, first record and last record. I still need to stop
> the user from creating a new record when on last record with the next
> record button.
> Do I use CurrentRecord in the click event? I found some code that
> might be a start (below). I am not sure how to do this. Thanks in
> advance.
> Function RecordNumber (pstrPreFix As String, pfrm As Form) As String
> On Error GoTo RecordNumber_Err
> Dim rst As Recordset
> Dim lngNumRecords As Long
> Dim lngCurrentRecord As Long
> Dim strTmp As String
> Set rst = pfrm.recordsetclone
> rst.MoveLast
> rst.bookmark = pfrm.bookmark
> lngNumRecords = rst.recordcount
> lngCurrentRecord = rst.absoluteposition + 1
> strTmp = pstrPreFix & " " & lngCurrentRecord & " of " &
> lngNumRecords
> RecordNumber_Exit:
> On Error Resume Next
> RecordNumber = strTmp
> rst.Close
> Set rst = Nothing
> Exit Function
> RecordNumber_Err:
> Select Case Err
> Case 3021
> strTmp = "New Record"
> Resume RecordNumber_Exit
> Case Else
> strTmp = "#" & Error
> Resume RecordNumber_Exit
> End Select
> End Function
> Rory Jakes