Re: On Error GoTo is not working



It is. I wondered why he is doing that, I guess he wants to skip a line so
it displays like:

Some Stuff On this Line

More Stuff After a Blank Line

"BruceM" wrote:

Just curious as to what Chr$(13) & Chr$(13). I would have thought it is two
carriage returns in succession.

"Klatuu" <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EEDBA4A7-27C9-4E81-B739-EAC9A8F7D398@xxxxxxxxxxxxxxxx
It is not checking for required fields anywhere in your code. Your
message
is not in the correct place. No error is generated because of a null
field.
Below is a revision of your code that may (if I didn't make an error)
correct
the problem:

Private Sub Command9_Click()
Dim strRequestID As String
Dim strTo As String
Dim strHeader As String
Dim strMessage As String
Dim strYourName As String
Dim strReason As String
Dim blnRequiredFieldIsMissing As Boolean

On Error GoTo Err_Command9_Click

If IsNull(Me.RequestID) Then
blnRequiredFieldIsMissing = True
Else
strRequestID = Me.RequestID
End If

If IsNull(Me.YourName) Then
blnRequiredFieldIsMissing = True
Else
strYourName = Me.YourName
End If

If IsNull(Me.Reason) Then
blnRequiredFieldIsMissing = True
Else
strReason = Me.Reason
End If

If blnRequiredFieldIsMissing Then
MsgBox "Required fields for this form are: Request ID, Date, Name,
and " _
& "Reason. If all the required fields are not filled in, your
form will " _
& "not be submitted.", vbOKOnly
Else
strTo = "jusss@xxxxxxxxxxxxx;jusss@xxxxxxxxx"
strHeader = "Password needed to Edit a Request"
strMessage = "A request for a password is needed to make the
following " _
& "change. Please view the details below and contact this
person
with " _
& "further instructions." & Chr$(13) & Chr$(13) _
& "Request ID: " & strRequestID & Chr$(13) & Chr$(13) _
& "Name: " & strYourName & Chr$(13) & Chr$(13) _
& "Reason: " & strReason & Chr$(13) & Chr$(13) _
& "Please do not reply to this automated email."

DoCmd.SendObject acSendNoObject, , , strTo, , , _
strHeader, strMessage, No, False

DoCmd.Close acForm, "frmRequestPassword"

MsgBox "Your request for a password has been sent. You will be " _
& "contacted with further instructions.", vbOKOnly, _
& "Password Request Sent"
End If

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:

MsgBox Err.Description
Resume Exit_Command9_Click

End Sub

Also, notice the difference in readability of the code above. Proper
indentation and white space makes it much easier for us humans to read,
but
the computer doesn't care.
"JNariss@xxxxxxxxx" wrote:

Hello,

I have a form with the following code that is not working properly.
This form is created from one simple table called tblRequestPassword
with all fields being required. Fields are RequestID, Name, Reason, and
Date.

I was hoping someone could take a look and perhaps see what errors are
in my code. What I want it to do is to check that all fields have a
value and if so then execute the SendObject command. However, it is not
executing an error if any of the fields are left blank it just runs the
SendObject.


Private Sub Command9_Click()
On Error GoTo Err_Command9_Click

Dim strTo As String
Dim strRequestID As String
Dim strMessage As String
Dim strYourName As String
Dim strReason As String

strTo = "jusss@xxxxxxxxxxxxx;jusss@xxxxxxxxx"
strRequestID = Me.RequestID
strYourName = Me.YourName
strReason = Me.Reason

strMessage = "A request for a password is needed to make the following
change. Please view the details below and contact this person with
further instructions." & Chr$(13) & Chr$(13) & _
"Request ID: " & strRequestID & Chr$(13) & Chr$(13) & _
"Name: " & strYourName & Chr$(13) & Chr$(13) & _
"Reason: " & strReason & Chr$(13) & Chr$(13) & _
"Please do not reply to this automated email."

DoCmd.SendObject acSendNoObject, , , strTo, , , "Password needed to
Edit a Request", strMessage, No, False
DoCmd.Close acForm, "frmRequestPassword"
MsgBox "Your request for a password has been sent. You will be
contacted with further instructions.", vbOKOnly, "Password Request
Sent"

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description & Chr$(13) & Chr$(13) & _
"Required fields for this form are: Request ID, Date, Name, and
Reason. If all the required fields are not filled in, your form will
not be submitted.", vbOKOnly
Resume Exit_Command9_Click

End Sub



Thank You,
Justine





.



Relevant Pages

  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... MsgBox "Required fields for this form are: Request ID, Date, Name, ...
    (microsoft.public.access.formscoding)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... Edit a Request", strMessage, No, False ...
    (microsoft.public.access.formscoding)
  • On Error GoTo is not working
    ... Dim strRequestID As String ... Dim strMessage As String ... Edit a Request", strMessage, No, False ...
    (microsoft.public.access.formscoding)
  • How can I do a loop?
    ... Dim strBrief_Description As String ... strMessage = "The following requesthave been moved into production: ... "For futher details regarding this request please go to the database ...
    (microsoft.public.access.formscoding)
  • Re: On Error GoTo is not working
    ... Dim strRequestID As String ... Dim blnRequiredFieldIsMissing As Boolean ... MsgBox "Required fields for this form are: Request ID, Date, ...
    (microsoft.public.access.formscoding)