Msgbox Troubles

T

thefonz37

So I have a form ("frm_Manage_Exceptions") with a listbox on it. When you
click on one of the items, it brings up a new form ("frm_Exception_Entry") in
which you can edit the item. When you are done editing, you click on a
hyperlink to close the editing form and return to the original form.
Ultimately, what I'd like to have happen is for there to be a prompt before
closing the editing form that contains the content of the form, so the user
can confirm whether or not the information is correct. Here's the code I
have for that:

Private Sub Label36_Click()
If Me.Dirty Then
msgResult = MsgBox("Please confirm that you will be using " &
cboExceptionType.Column(1) & " from " & _
start_time & " to " & end_time & " on " & date & ".", vbOKCancel)
If (msgResult = vbOK) Then
DoCmd.Close acForm, "frm_Exception_Entry"
Else: End If
Else
DoCmd.Close acForm, "frm_Exception_Entry"
End If
End Sub

Everything works fine, except for the fact that if you click "Cancel" in the
message box, it leaves the editing form open, as intended, but sends it to
the background, moving the form with the listbox on it to the front. It's a
little thing, but ultimately it negatively impacts the flow of the
application.

Any ideas why it's not working correctly?
 
S

Scott Whetsell, A.S. - WVSP

Try:

If Me.Dirty Then
Select Case MsgBox("Please confirm that you will be using " & _
cboExceptionType.Column(1) & " from " & start_time & " to " & _
end_time & " on " & date & ".", vbOKCancel)
Case 6 ' Okay Button
DoCmd.Close acForm, "frm_Exception_Entry"
Case Else ' Everything else
Exit Sub
Else:
DoCmd.Close acForm, "frm_Exception_Entry"
End If
 
D

Dirk Goldgar

thefonz37 said:
So I have a form ("frm_Manage_Exceptions") with a listbox on it. When you
click on one of the items, it brings up a new form ("frm_Exception_Entry")
in
which you can edit the item. When you are done editing, you click on a
hyperlink to close the editing form and return to the original form.
Ultimately, what I'd like to have happen is for there to be a prompt
before
closing the editing form that contains the content of the form, so the
user
can confirm whether or not the information is correct. Here's the code I
have for that:

Private Sub Label36_Click()
If Me.Dirty Then
msgResult = MsgBox("Please confirm that you will be using " &
cboExceptionType.Column(1) & " from " & _
start_time & " to " & end_time & " on " & date & ".",
vbOKCancel)
If (msgResult = vbOK) Then
DoCmd.Close acForm, "frm_Exception_Entry"
Else: End If
Else
DoCmd.Close acForm, "frm_Exception_Entry"
End If
End Sub

Everything works fine, except for the fact that if you click "Cancel" in
the
message box, it leaves the editing form open, as intended, but sends it to
the background, moving the form with the listbox on it to the front. It's
a
little thing, but ultimately it negatively impacts the flow of the
application.

Any ideas why it's not working correctly?


I suspect it's because you are using a hyperlink to go back to the original
form. Am I right in thinking that your label, Label36, is the hyperlink?
(I'd recommend using more meaningful names for controls you intend to work
with in code, by the way.) If this label is a hyperlink to
frm_Manage_Exceptions, clicking it will send the focus back to that form
regardless of whether you close frm_Exception_Entry or not.

I'd recommend using a command button instead of this label, with no
hyperlink property. Just put your code in that button's Click event, and
then your frorm will retain the focus if the user chooses Cancel in the
message box.

As an aside, I think it would be clearer if you rewrote this:
If (msgResult = vbOK) Then
DoCmd.Close acForm, "frm_Exception_Entry"
Else: End If

.... as this:

If (msgResult = vbOK) Then
Me.Dirty = False ' force record save
DoCmd.Close acForm, Me.Name, acSaveNo
End If
 

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