Solved

acNext takes me to blank record

Posted on 2000-03-23
7
570 Views
Last Modified: 2012-05-04
I'm using a button on a form to move to the next record. I placed the code DoCmd.GoToRecord , , acNext behind the button. It works fine except users are able to scroll through all the records until they get to the end and then it's blank. However, acLast does not take them to a blank record. How can I get acnext to stop vefore it goes to far. The problem is they are going to the blank record and trying to enter new records there instead of using the add records button.
0
Comment
Question by:scully12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Accepted Solution

by:
Viesturs earned 50 total points
ID: 2649675
You can insert before
DoCmd.GoToRecord , , acNext
the code
Me.AllowAdditions = False
where Me is Active form
and when you wish
DoCmd.GoToRecord , , acNewRec
then insert before
Me.AllowAdditions = true.

Maybe this can help.
0
 
LVL 2

Expert Comment

by:goyam
ID: 2649715
Hi,
you may test if you are on the last record:
If Me.CurrentRecord <> Me.Count Then
    DoCmd.GoToRecord , , acNext
End If
Regards
0
 
LVL 7

Expert Comment

by:Dedushka
ID: 2649769
Hi scully12.
You can just go back to previous record:
Private Sub Command12_Click()
  DoCmd.GoToRecord , , acNext
  If Me.NewRecord Then DoCmd.GoToRecord , , acPrevious
End Sub

Good luck,
Dedushka
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:goyam
ID: 2649805
Sorry, I wanted to write
If Me.CurrentRecord <> Me.RecordsetClone.RecordCount Then
        DoCmd.GoToRecord , , acNext
End If
 and not Me.count
Best regards
0
 
LVL 2

Expert Comment

by:goyam
ID: 2649806
Sorry, I wanted to write
If Me.CurrentRecord <> Me.RecordsetClone.RecordCount Then
        DoCmd.GoToRecord , , acNext
End If
 and not Me.count
Best regards
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 2649945
Viesturs has it.  Just turn off AllowAdditions and then turn it on through code when you press the AddRecord button.  
You probably already have this, but you should probably capture the EndOfRecordset error when you use those buttons.  Those are the errors you will get if you try to go past the last record, or go to a record before the first one with those buttons.
In the NextRecord button code:

Sub btnNextRecord_Click()
On Error Goto errorhandler
  DoCmd.GoToRecord , , acNext
Goto SkipErrorhandler:
ErrorHandler:
  Select Case err.number
  Case 2105
  Case Else
     msgbox "Err# " & err.number & vbCrLf & err.description
  End Select
  Resume Next
SkipErrorHandler:  
End Sub

You can use this in the Previous button code to, just change the gotoRecord argument to acPrevious

Hope this helps---CJSWIMMER
0
 

Author Comment

by:scully12
ID: 2650681
I think any of the answers I was given would have worked so thanks to everyone. However, I went with Viesturs answer for whatever reason. Thanks,
Scully12
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question