Solved

acNext takes me to blank record

Posted on 2000-03-23
7
552 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

816 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

10 Experts available now in Live!

Get 1:1 Help Now