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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Navigation Issues 1

Status
Not open for further replies.

ScottXJ

Programmer
Aug 14, 2002
51
CA
Hi all,

I am having a small problem with the navigation buttons on one of my forms. When I go to the last record and then click the "Next Record" button, I am taken to a blank record. This does not happen when I go to the first record and then click the "Previous Record" button. In that case, I get the "Can't go to specified record" error as I should. I am wondering if the fact that I have some default values set for certain fields is causing the problem here. The reason I ask, is that if go to this "blank" record and then clicn on the "Next Record" button, I get the error message as I should.

Any help or suggestions would be appreciated!

Thanks,

Scott.
 
You are seeing the 'blank record' which Access offers if you want to create a new record in the table, via the form.

A simple way to achieve the effect you require, is to edit the form properties, and set the Allow Additions property on the [Data] tab to 'No'.

Now you will not be able to add new records via the form, and your [Next Record] button will behave as you require.

If you want to be able to insert new records through the form, but change the way the [Next Record] button behaves, you will need to add some extra VBA code to the button's On_Click event. Example:
Code:
Dim lngRecordCount As Long

lngRecordCount = DCount([EmpID], "tblEmployees")
If Me.CurrentRecord = lngRecordCount Then
    MsgBox "error"
Else
    DoCmd.GoToRecord , , acNext
End If
This code replaces the original, single line of code which the Access wizard creates for the button, which is just:
Code:
    DoCmd.GoToRecord , , acNext

Note that using 'DCount' in this way, may slow things down slightly if your table contains many records.

I hope that this is useful.

Bob Stubbs
 
Thanks so much Bob!

I used the form property setting of Allow Additions and set it to No. This solution was just what I was looking for.

Thanks again,

Scott.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top