UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> repeated message box    
 
   
Dani50
post Nov 3 2008, 06:49 AM
Post #1

UtterAccess Member
Posts: 49
From: NW England, UK



Hello,
I have a subform which is displayed in continuous form where edits and additions are not allowed but deletions are.
This subform's On_delete event is as follows:

Private Sub Form_Delete(Cancel As Integer)
Dim strText, strAnswer As String
strText = "Are you sure you want to delete '" & Me.FullText & "'?"
strAnswer = MsgBox(strText, vbYesNo)
If strAnswer = vbYes Then
Cancel = False
Else
Cancel = True
End If
End Sub

The problem (which is only an irritation) is that if the user chooses "no" the mesage box appears again before acting on the response. If they choose "yes" it doesn't. Changing which button has the focus makes no difference. Under 'confirm' on the 'edit/find' tab of 'options' I have "record changes" set to "off" so I cannot see that it is an automated message. Any suggestions as to the reason it does this twice and what I can do about it.

Dani.
Go to the top of the page
 
+
TheForce
post Nov 3 2008, 08:17 AM
Post #2

UtterAccess Veteran
Posts: 401
From: NW England



Not sure but have you tried a Me.Undo after Cancel = True?
Go to the top of the page
 
+
Willem
post Nov 3 2008, 08:35 AM
Post #3

UtterAccess Veteran
Posts: 464
From: Amersfoort, The Netherlands



Hi,

Hmm... odd, when I replicate your problem I do not get a second msgbox when I choose 'No'. When I choose 'Yes' I do get an extra msgbox which can be suppressed by using:

CODE
DoCmd.SetWarnings False


See attached for my db, do you get the same problem there?
Attached File(s)
Attached File  test.zip ( 14.93K ) Number of downloads: 0
 
Go to the top of the page
 
+
Alan_G
post Nov 3 2008, 09:19 AM
Post #4

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,882
From: Devon UK



Hi

In your Dim statement, you're only actually dimensioning strAnswer as a string (which funnily enough isn't correct anyway - it should be an integer). strText is being dimensioned as a Variant. To dimension multiple variables on the same line seperated by commas, you need to explicitly declare the variable type for each one.

I think I'd put the delete code behind a command button instead of the forms Delete event, but you could try

CODE
Private Sub Form_Delete(Cancel As Integer)

Dim strText As String, intAnswer As Integer

strText = "Are you sure you want to delete " & Chr(34) & Me.FullText & Chr(34) & "?"

intAnswer = MsgBox(strText, vbYesNo)

If intAnswer = vbNo Then

Cancel = True

End If

End Sub


***Untested
Go to the top of the page
 
+
Dani50
post Nov 3 2008, 09:53 AM
Post #5

UtterAccess Member
Posts: 49
From: NW England, UK



Thanks a lot for all your replies I have tried them all and I am still getting the same problem. I wonder if it could be Vista?
Thanks for the tips Alan, I'll do as you suggest.
Originally I had a list box and a command button but when I changed to a a cts form as a subform I wasn't sure how to refer to the selected record. The things I tried didn't work, but I might have another go.
Dani.
Go to the top of the page
 
+
TheForce
post Nov 3 2008, 10:46 AM
Post #6

UtterAccess Veteran
Posts: 401
From: NW England



Try replicating the problem in a new db file. It would help to rule out file corruption.
Go to the top of the page
 
+
JVanKirk
post Nov 3 2008, 10:57 AM
Post #7

UtterAccess VIP
Posts: 3,872
From: Fort Drum, NY



And on the note of corruption, have your tried a compact and repair?

J
Go to the top of the page
 
+
Alan_G
post Nov 3 2008, 10:59 AM
Post #8

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,882
From: Devon UK



Wouldn't have thought it would be anything to do with Vista. You can still get the selected record to delete even though it's now a subform and not a listbox. I'd definitely go with the command button. If, for example, your command button was on your main form then code such as (assuming ReordID to be numeric)

CODE
Dim strText As String, intAnswer As Integer
strText = "Are you sure you want to delete " & Chr(34) & Me.NameOfSubFormControl.Form!FullText & Chr(34) & "?"
intAnswer = MsgBox(strText, vbYesNo)
If intAnswer = vbYes Then
Currentdb.Execute "DELETE RecordID FROM YourTable WHERE RecordID = " & Me.NameOfSubFormControl.Form!RecordID,dbFailOnError
Me.NameOfSubFormControl.Form.Requery
End If


should do it.

**Untested
Go to the top of the page
 
+
Dani50
post Nov 4 2008, 03:49 AM
Post #9

UtterAccess Member
Posts: 49
From: NW England, UK



That worked perfectly Alan.
Thank you all for your help.
Dani.
Go to the top of the page
 
+
Alan_G
post Nov 4 2008, 03:27 PM
Post #10

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,882
From: Devon UK



No problem - glad it worked for you (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 03:25 PM