Solved

acNext takes me to blank record

Posted on 2000-03-23
7
541 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
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now