subform controls (checkbox) events

Robert Saye

Registered User.
Local time
Today, 16:54
Joined
Jun 19, 2000
Messages
49
Hello all,

I have two subforms on my main form. One subform has a check box on it, when the user checks it, I would like to open a msgbox asking if they are sure. (A append and delete query fire off at main form close). I would like the msgbox to open and then if they click yes to run my 2 queries (instead of at form close). I have the following code in the subform:

Private Sub CheckWhenComplete_BeforeUpdate(Cancel As Integer)
'If the user really meant to check the box, then run append & delete queries
Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

If CheckWhenComplete = 1 Then
strMessage = "Did you complete Action Item? This will cause the line to be deleted and sent to the comments table."
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbCancel Then
CheckWhenComplete.SetFocus
Cancel = True
End If
End If

End Sub
 
You have it more complicated than it needs to be. Shorter code is better. Try this:

Private Sub CheckWhenComplete_AfterUpdate(Cancel As Integer)

If MsgBox("Did you complete Action Item? This will cause the line to be deleted and sent to the comments table, vbOKCancel, "Deletion Confirmation") _
= vbCancel Then
MsgBox "No line was deleted.", , "Action Canceled"
CheckWhenComplete = False
Exit Sub
Else
RUN_YOUR_TWO_QUERIES_HERE
MsgBox "Line was deleted.", , "Deletion Execution"

End Sub
 

Users who are viewing this thread

Back
Top Bottom