Rabu, 05 April 2017

Re: [MS_AccessPros] Error Handling MS Template

 

David-


The first On Error tells Access to ignore any errors and go on to the next statement.  It's possible that the acCmdSaveNow will error out.  Note that the very next If statement checks to see if an error was generated, and if so, displays the error and exits.  The remainder of the code is fairly straightforward.  If there's no value in ID, then it makes a sound and exits.  If ID has a value, it saves it in a TempVar, closes the current form, opens a report with the ID filtered, prints it, then opens another form filtered.  Finally, it  clears the TempVar and exits.  The cmdPrint_Click_Err code isn't referenced anywhere, so it never executes.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Apr 5, 2017, at 7:47 PM, david.pratt@outlook.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



For my education, I am trying to convert some MS templates from macros to code.  Can someone explain why the various MS template subs have two different error handling statements, one after the other, as below?  What error would the first error statement handle?  I assume the first error statement gets turned off as soon as the code reaches the second error statement?

'Private Sub cmdPrint_Click()
'On Error GoTo cmdPrint_Click_Err
'
'
'    On Error Resume Next
'    If (Form.Dirty) Then
'        DoCmd.RunCommand acCmdSaveNow
'    End If
'    If (MacroError.Number <> 0) Then
'        DoCmd.Beep
'        MsgBox MacroError.Description, vbOKOnly, ""
'        Exit Sub
'    End If
'    On Error GoTo 0
'    If (IsNull(ID)) Then
'        DoCmd.Beep
'        Exit Sub
'    End If
'    TempVars.Add "FIlterID", ID.Value
'    DoCmd.Close , ""
'    DoCmd.OpenReport "Task Details", acViewReport, "", "[TaskID]=" & TempVars!FilterID, acNormal
'    DoCmd.RunCommand acCmdPrint
'    DoCmd.OpenForm "frmTaskDetails", acNormal, "", "[TaskID]=" & TempVars!FilterID, , acNormal
'    TempVars.Remove "FIlterID"

'cmdPrint_Click_Exit:
'    Exit Sub
'
'cmdPrint_Click_Err:
'    MsgBox Error$
'    Resume cmdPrint_Click_Exit
'
'End Sub





__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar