Stop a popoup

G

Guest

I have a the following event procedure in the form's before update. the
problem is that it if everything is filled out right the msgbox keeps popping
up all the time but it does not indicate what is incomplete, but on the other
had if something is incomplete, it will say what it is but still have the
popup again, any reason why?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
Exit Sub

End Sub
 
G

Guest

There is no indication if everything OK,Try this

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String
strControl =""
If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

If strControl <> "" then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
end if
Exit Sub

End Sub
 
G

Guest

Thanks that worked ok for me, although there is still another 2nd popup that
comes up if the infor was not entered correcctly

domenuitem action was cancelled
 
G

Graham Mandeno

The problem is that your last two lines (MsgBox and Cancel=true) are not in
any kind of conditional statement, so they are being executed whether the
data is correct or not.

Try rearranging your code to set Cancel=True if a problem is found, then
check the value of Cancel to decide whether to show the message:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
Cancel = True
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
Cancel = True
End If

If Cancel Then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
End If

End Sub
 
G

Guest

Try and trap this message and make the code ignore it

Private Sub Form_BeforeUpdate(Cancel As Integer)
On error goto Form_BeforeUpdate_Err
Dim strControl As String
strControl =""
If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

If strControl <> "" then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
end if

Form_BeforeUpdate_Exit:
Exit sub
Form_BeforeUpdate_Err:
msgbox err
resume Form_BeforeUpdate_Exit
End Sub

After you get the error number displayed chenge the error capture to

Form_BeforeUpdate_Err:
if err <> numberdisplayed
msgbox error
end if
resume Form_BeforeUpdate_Exit
=======================================
 
G

Guest

I did what you said but it kept bringing the popup, it has no error number it
only states

DoMenuItem action was Cancelled

I aslo tried to get rid of cancel = true after the msgbox.

JOM!
 
G

Guest

I did what you said but it kept bringing the popup, it has no error number it
only states

DoMenuItem action was Cancelled

Graham Mandeno said:
The problem is that your last two lines (MsgBox and Cancel=true) are not in
any kind of conditional statement, so they are being executed whether the
data is correct or not.

Try rearranging your code to set Cancel=True if a problem is found, then
check the value of Cancel to decide whether to show the message:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
Cancel = True
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
Cancel = True
End If

If Cancel Then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
End If

End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

JOM said:
I have a the following event procedure in the form's before update. the
problem is that it if everything is filled out right the msgbox keeps
popping
up all the time but it does not indicate what is incomplete, but on the
other
had if something is incomplete, it will say what it is but still have the
popup again, any reason why?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
Exit Sub

End Sub
 
G

Graham Mandeno

DoMenuItem action was Cancelled

This message is coming from a different part of your code - the bit that is
requesting that the record be saved. Your Form_BeforeUpdate procedure is
preventing the record from being saved by setting Cancel=True. It does this
because your rule says a record cannot have a blank reason or a blank date.

However, all the code that is trying to save the record knows is that it
tried and, for some reson, failed. You need to tell *that* code to ignore
the error.

Do you have a "Save record" command button? If so, then the code in its
Click event procedure should look something like this:

Private Sub cmdSaveRecord_Click()
On Error GoTo ProcErr
DoCmd.RunCommand acCmdSaveRecord
ProcEnd:
Exit Sub
ProcErr:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Cannot save record"
End If
Resume ProcEnd
End Sub

This code attenpts to save the record (DoCmd...) and if any error occurs, it
goes to the error handling code at ProcErr. Here, the error is checked, and
a message is displayed only if the error code is not 2501 (command was
cancelled).

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


JOM said:
I did what you said but it kept bringing the popup, it has no error number
it
only states

DoMenuItem action was Cancelled

Graham Mandeno said:
The problem is that your last two lines (MsgBox and Cancel=true) are not
in
any kind of conditional statement, so they are being executed whether the
data is correct or not.

Try rearranging your code to set Cancel=True if a problem is found, then
check the value of Cancel to decide whether to show the message:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
Cancel = True
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
Cancel = True
End If

If Cancel Then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
End If

End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

JOM said:
I have a the following event procedure in the form's before update. the
problem is that it if everything is filled out right the msgbox keeps
popping
up all the time but it does not indicate what is incomplete, but on the
other
had if something is incomplete, it will say what it is but still have
the
popup again, any reason why?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
Exit Sub

End Sub
 
G

Guest

That did the trick thanks!





Graham Mandeno said:
DoMenuItem action was Cancelled

This message is coming from a different part of your code - the bit that is
requesting that the record be saved. Your Form_BeforeUpdate procedure is
preventing the record from being saved by setting Cancel=True. It does this
because your rule says a record cannot have a blank reason or a blank date.

However, all the code that is trying to save the record knows is that it
tried and, for some reson, failed. You need to tell *that* code to ignore
the error.

Do you have a "Save record" command button? If so, then the code in its
Click event procedure should look something like this:

Private Sub cmdSaveRecord_Click()
On Error GoTo ProcErr
DoCmd.RunCommand acCmdSaveRecord
ProcEnd:
Exit Sub
ProcErr:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Cannot save record"
End If
Resume ProcEnd
End Sub

This code attenpts to save the record (DoCmd...) and if any error occurs, it
goes to the error handling code at ProcErr. Here, the error is checked, and
a message is displayed only if the error code is not 2501 (command was
cancelled).

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


JOM said:
I did what you said but it kept bringing the popup, it has no error number
it
only states

DoMenuItem action was Cancelled

Graham Mandeno said:
The problem is that your last two lines (MsgBox and Cancel=true) are not
in
any kind of conditional statement, so they are being executed whether the
data is correct or not.

Try rearranging your code to set Cancel=True if a problem is found, then
check the value of Cancel to decide whether to show the message:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
Cancel = True
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
Cancel = True
End If

If Cancel Then
MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
End If

End Sub

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a the following event procedure in the form's before update. the
problem is that it if everything is filled out right the msgbox keeps
popping
up all the time but it does not indicate what is incomplete, but on the
other
had if something is incomplete, it will say what it is but still have
the
popup again, any reason why?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strControl As String

If Me.Request = True And IsNull(Me.reason) Then
strControl = strControl & "Reasons " & vbCrLf
Me.reason.SetFocus
End If

If IsNull(Me.DateRequested) Then
strControl = strControl & "Date Requested" & vbCrLf
Me.DateRequested.SetFocus
End If

MsgBox "The following information is required:" & vbCrLf & strControl,
vbInformation, "Incomplete Information"
Cancel = True
Exit Sub

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top