Modify Message Box Cancel Button

  • Thread starter pushrodengine via AccessMonster.com
  • Start date
P

pushrodengine via AccessMonster.com

Part of the code below brings up a message box letting the user know that
they must press Add Incident button to save the incident.

The problem I’m having is when the Cancel button is pressed it behaves the
same way the OK button. The OK button works properly. I would like the Cancel
to return user to the form so that information may be re-entered.

How do I modify the code to make that possible?
_____________________________________________________________________
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Dim strWhere As String
Dim varResult As Variant
Dim iAns As Integer

If Me!chkOKToClose = False Then
iAns = MsgBox("Please use the Add Incident Button to Save the
Incident" & " or Select Cancel to Re-enter Incident Log", vbOKCancel, "Re-
enter Incident Log")
Cancel = True
If iAns = vbCancel Then
Me.Undo

End If
End If

strWhere = "IncidentID Like """ & Format(Date, "yy") & "*"""
varResult = DMax("IncidentID", "tblIncidentLog", strWhere)

If IsNull(varResult) Then
Me.IncidentID = Format(Date, "yy") & "-0001"
Else
Me.IncidentID = Left(varResult, 3) & _
Format(Val(right(varResult, 4)) + 1, "0000")
End If
End If
End Sub
_____________________________________________________________________


Thanks
 
S

Steve Schapel

Pushrod,

I'm not 100% clear what this is for, but anyway I'll offer a suggestion...

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Dim strWhere As String
Dim varResult As Variant
Dim iAns As Integer

If Me!chkOKToClose = False Then
iAns = MsgBox("Please use the Add Incident Button to Save the
Incident" & vbCrLf & "or Select Cancel to Re-enter Incident Log",
vbOKCancel, "Re-
enter Incident Log")
Cancel = True
If iAns = vbCancel Then
Me.Undo
Else
strWhere = "IncidentID Like """ & Format(Date, "yy") & "*"""
varResult = DMax("IncidentID", "tblIncidentLog", strWhere)
If IsNull(varResult) Then
Me.IncidentID = Format(Date, "yy") & "-0001"
Else
Me.IncidentID = Left(varResult, 3) & _
Format(Val(right(varResult, 4)) + 1, "0000")
End If
End If
End If
End If
End Sub
 
P

pushrodengine via AccessMonster.com

I'm not 100% clear what this is for, but anyway I'll offer a suggestion...

The part of the code I'm having problems with is when the Cancel button is
pressed in the message box the database closes.

If Me!chkOKToClose = False Then
iAns = MsgBox("Please use the Add Incident Button to Save the
Incident" & vbCrLf & "or Select Cancel to Re-enter Incident Log",
vbOKCancel, "Re-
enter Incident Log")
Cancel = True
If iAns = vbCancel Then
Me.Undo

I would like when the Cancel button is pressed the database doesn't close.

Do I replace the "Me.Undo" with something else?

Thanks
 
S

Steve Schapel

Pushrod,

I can't see anything anywhere in the code that will close the database.

Me.Undo will reverse any data entry/edits done on the form.

Cancel = True will cancel the Update event of the form, which means that
the record is not saved. But this is being applied regardless of which
message box button is clicked... assuming chkOKToClose = False that is.

But the closing of the form or database is a mystery.
 
P

pushrodengine via AccessMonster.com

Steve Schapel,
How can I get rid of the cancel button all together in the the message box?

Thank you everyone for your help!


If Me!chkOKToClose = False Then
iAns = MsgBox("Please use the Add Incident Button to Save the
Incident" & vbCrLf & "or Select Cancel to Re-enter Incident Log",
vbOKCancel, "Re-
enter Incident Log")
Cancel = True
If iAns = vbCancel Then
Me.Undo
 
S

Steve Schapel

Remove the vbOKCancel from your code:
iAns = MsgBox("Please ... Re-enter Incident Log", , "Re-enter Incident Log")
 

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

Similar Threads


Top