Navigation Buttons - Not Allowing New Record Creation with Next Record 
Author Message
 Navigation Buttons - Not Allowing New Record Creation with Next Record

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



Mon, 04 Apr 2005 05:52:05 GMT  
 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




Mon, 04 Apr 2005 07:05:32 GMT  
 Navigation Buttons - Not Allowing New Record Creation with Next Record

Quote:

> 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



> > 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


Thanks Shane.


Mon, 04 Apr 2005 20:49:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Preventing next record button adding new records.

2. next record button creating new records

3. Navigation buttons, Preventing inadvertant record creation

4. Navigation Buttons, Preventing inadvertant record creation

5. Stop allowing creation of records based on record criteria

6. capturing the record number and total records in a form with no navigation buttons

7. Is There any Form Event for moving from record to record when using Navigation button

8. how to add new record to a subform while disable navigation button

9. How Do I Detect a New Record from the Navigation Buttons

10. Form Navigation Button creating new record


 
Powered by phpBB® Forum Software © phpBB Group