Solved

acNext takes me to blank record

Posted on 2000-03-23
7
577 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 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