L
lmcc via AccessMonster.com
When I converted the macro to code. Here is what I got:
On Error GoTo copyofrecord1_Err
With CodeContextObject
On Error Resume Next
DoCmd.RunCommand acCmdSelectRecord
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdCopy
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdSelectRecord
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdPaste
End If
If (.MacroError <> 0) Then
Beep
MsgBox .MacroError.Description, vbOKOnly, ""
End If
End With
copyofrecord1_Exit:
Exit Function
copyofrecord1_Err:
MsgBox Error$
Resume copyofrecord1_Exit
End Function
What does the "With CodeContextObject" and "(.MacroError = 0)" mean?
Since I don’t quite understand the code, I decided to create my own code. I
created this code to copy a record to a new record.
Private Sub cmdCopyRecord_Click()
On Error GoTo ErrorHandler
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdPaste
Exit:
Exit Sub
ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume Exit
End Sub
My concern is that in the macro they do error checking throughout. Should I
be doing that also? Is my code okay?
Any opinions are appreciated.
On Error GoTo copyofrecord1_Err
With CodeContextObject
On Error Resume Next
DoCmd.RunCommand acCmdSelectRecord
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdCopy
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdSelectRecord
End If
If (.MacroError = 0) Then
DoCmd.RunCommand acCmdPaste
End If
If (.MacroError <> 0) Then
Beep
MsgBox .MacroError.Description, vbOKOnly, ""
End If
End With
copyofrecord1_Exit:
Exit Function
copyofrecord1_Err:
MsgBox Error$
Resume copyofrecord1_Exit
End Function
What does the "With CodeContextObject" and "(.MacroError = 0)" mean?
Since I don’t quite understand the code, I decided to create my own code. I
created this code to copy a record to a new record.
Private Sub cmdCopyRecord_Click()
On Error GoTo ErrorHandler
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdPaste
Exit:
Exit Sub
ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume Exit
End Sub
My concern is that in the macro they do error checking throughout. Should I
be doing that also? Is my code okay?
Any opinions are appreciated.