Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2007

Tip: Looking for answers? Try searching our database.

Trapping for Last record on Cont. Form, I'm getting desperate...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
efandango - 28 Mar 2007 21:12 GMT
Does anyone know how I can make this code trap for the Last Record

The procedure cycles through a number of the same selection box on one
continuous form, and if the choice is correct, then copies the data to
another field on the target field/form. Then moves to the next selection,
until it fills in the last blank field record, that’s where it bombs out with
a no next record error: At the moment I have a quick fix in the shape of an
On Error line, but it’s not ideal as It realies on a natural error rather
than clean elegant code. I have tried every which way to get my head round
this, but have got nowhere for nearly 3 days.

Private Sub Waypoint_Selector_Click()
'~~~~~~~~~~~~~~~~~~~~~~
   'set up Error Handler
 On Error GoTo Proc_Err

'~~~~~~~~~~~~~~~~~~~~~~

If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector
'If the Target field is empty then place the Selection from the Selector
Form into the Target Field on Target Form
End If

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] <>
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Null
'This checks if the selection is wrong, if so, then reset (blank) the
Waypoint Target
End If

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] =
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Parent.frm_Run_Test.SetFocus
Parent.frm_Run_Test.Form.Waypoint_Combo.SetFocus
DoCmd.GoToControl "Direction_Combo"
RunCommand acCmdRecordsGoToNext
'This sets the Focus back to the Run Test Form/Direction Control

End If
Proc_Err:
   'MsgBox "All fields are filled"

End Sub
George Nicholson - 28 Mar 2007 22:29 GMT
Quite often "clean elegant code" means allowing for the possibility of an
error & reacting to it. This is one of them.

Either rely on the EOF (end of file) property of the Form's Recordset to
tell you if you've "gone past" available records, or simply assume that if
you raise an error from GoToNext that you've hit EOF. In either case, you
can't reliably test for it before trying to move.

   On Error GoTo Next
    RunCommand acCmdRecordsGoToNext
   If Err.Number = 0 then
       'No error
   Else
       'No record is available. Go Back to Last record of recordset
       RunCommand acCmdRecordsGoToLast
       ' ?Add MsgBox here?
   End If
    'Restore original Error handler, reset Err object
    On Error GoTo Proc_Err

HTH,

> Does anyone know how I can make this code trap for the Last Record
>
[quoted text clipped - 42 lines]
>
> End Sub
efandango - 29 Mar 2007 00:30 GMT
George,

Do I paste your code in verbatim, at the beggining of my code?

Your first line:  'On Error GoTo Next' Just comes back as Red Highlighted
error code?
Is it because Maybe 'Next' is a reserved word?.

Also, what does your code actually do in relation to my code, or is it just
a generic example?. Apart from relieving my code of errors, I also want to
the code to be able to recognise when it has reached the last record, because
I want to assign some additonal actions to that occurance.

> Quite often "clean elegant code" means allowing for the possibility of an
> error & reacting to it. This is one of them.
[quoted text clipped - 64 lines]
> >
> > End Sub
Douglas J. Steele - 29 Mar 2007 12:51 GMT
Typo on George's part. It should be

On Error Resume Next

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> George,
>
[quoted text clipped - 86 lines]
>> >
>> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.