uncheck all that are checked

A

Angi

I have a msgbox that asks the user to confirm deleting records. If the
user presses cancel, I want to set each checkbox back to No. I've
tried .requery, .repaint, if...then. Nothing has worked. I think I
need something like a For each...then. I've looked at the help and
can't find anything on that. I'm also getting an error that I can't
assign a value to me.cDelete. TIA Here's my code now:

Private Sub Form_Close()
Dim msgboxresult As String

msgboxresult = MsgBox("You are about to delete contacts. Are
you sure you want to continue?", vbOKCancel, "WARNING!")

If msgboxresult = vbOK Then
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE Contactmain.*, contactmain.cdelete " _
& "FROM contactmain WHERE (((contactmain.cdelete)=True));"
Forms!companymain.Requery
DoCmd.SetWarnings True
End If

If msgboxresult = vbCancel Then
If Me.CDelete = yes Then
Me.CDelete = no
End If
End If

End Sub
 
F

fredg

I have a msgbox that asks the user to confirm deleting records. If the
user presses cancel, I want to set each checkbox back to No. I've
tried .requery, .repaint, if...then. Nothing has worked. I think I
need something like a For each...then. I've looked at the help and
can't find anything on that. I'm also getting an error that I can't
assign a value to me.cDelete. TIA Here's my code now:

Private Sub Form_Close()
Dim msgboxresult As String

msgboxresult = MsgBox("You are about to delete contacts. Are
you sure you want to continue?", vbOKCancel, "WARNING!")

If msgboxresult = vbOK Then
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE Contactmain.*, contactmain.cdelete " _
& "FROM contactmain WHERE (((contactmain.cdelete)=True));"
Forms!companymain.Requery
DoCmd.SetWarnings True
End If

If msgboxresult = vbCancel Then
If Me.CDelete = yes Then
Me.CDelete = no
End If
End If

End Sub

I assume the check box [cdelete] is a field in the table, not just a
control on the form.
Let's use the Execute method, so there is no need to turn Warnings on
or off.
Note: If you Delete TableName.* you going to delete all the fields in
that record, so there is no need to name the cdelete also.

Private Sub Form_Close()

If MsgBox("You are about to delete contacts. Are you sure you want
to continue?", vbOKCancel, "WARNING!") = vbOK Then

CurrentDb.Execute "DELETE Contactmain.* FROM contactmain WHERE
contactmain.cdelete=True;" , dbFailOnError
Else
CurrentDb.Execute "Update Contactmain Set ContactMain.cdelete = 0;",
dbFailOnError

End If
 
A

Angi

Fred,
Thanks! Works great. I've never used the execute method. I'm gonna
have to see what else I can do with that.

Thanks again,
Ang
 

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