Access macro - failed to go to the last record after new month is added

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have the macro below for Access however after a new month is added, the screen just go back to the first month record instead of staying in the last record. I have used DoCmd.GoToRecord , , acLast but it still doesn't work.

Please can anybody tell me what have I done wrong? Many thanks.





Private Sub nextMonth_Click()
Dim newRecordResponse As Integer
Dim recordNumber As Long
If DCount("[monthID]", Screen.ActiveForm.RecordSource) = Screen.ActiveForm.CurrentRecord Then
newRecordResponse = MsgBox("This is the last record. " & _
"Do you want to create a new reporting month for " & _
vbCrLf & DateSerial(Year(Screen.ActiveForm.monthID), Month(Screen.ActiveForm.monthID) + 2, 0) & _
"?", vbYesNo)
If newRecordResponse = vbYes Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "q_appendStrategicProjects"
DoCmd.OpenQuery "q_appendStrategicProjectFinance"
DoCmd.SetWarnings False
Screen.ActiveForm.Requery
DoCmd.GoToRecord , , acLast

Else
End If
Else
DoCmd.GoToRecord , , acNext
End If
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Thanks, unfortunately it stills go to the first month record after a new month record is added by using acfirst.
 
Upvote 0
at the end of your sub you then use

DoCmd.GoToRecord , , acNext

was that intentional
 
Upvote 0
Yes, as so users can click the month button to select the next record. I have tried to changed both to acFirst, however it still went back to the first month record after a new month record is added. Also, since the last one is changed to acFirst, the record stays with the first one and not allowing me to select the next.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top