Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command button to clear flags on form's records 1

Status
Not open for further replies.

doctorswamp

Technical User
Jul 15, 2003
133
GB
Hi

Have a form that lists people's names, each with a tickbox to allow selection for later use. I'd like a button to clear all existing ticks.

Since the form is in datasheet view I can't see a way of container form with no data source and dropped the datasheet into it.

If the form is called frmContainer and the datasheet is called frmPickList, with tickbox called Flag, how do I get a command button to clear all existing ticks.

Or is there a better way of setting about this? Subsidiary question is whether it's right that a form in datasheet view can't contain command buttons?
 
A datasheet form cannot have command buttons. Have you considered Continuous Forms, which are similar, but with more control? For example, you could put a command button in the header. I guess the flags are bound, so the easiest thing is to run SQL through code or a query to clear your flags.
 
. . . and you can make a Continuous Form look just like a dataSheet!

Calvin.gif
See Ya! . . . . . .
 
Thanks Remou, and TheAceMan - you guys are great.

To clear ticks in the continuous form (which does look like a datasheet!) I've used a command button with the code below to run an update query on the form's record source. Is this a bit clumsy?

Without the acSaveRecord line it cleared everything but the last item ticked, but it now works properly

--------------

If MsgBox("Sure you want to clear flags?", vbOKCancel) = vbOK Then

'First save the last record, otherwise all but it are updated
'by the query

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'Temporarily suspend Microsoft warnings
DoCmd.SetWarnings False

'Run update query to remove all flags
On Error GoTo Err_cmdClearFlags_Click

DoCmd.Save

Dim stDocName As String

stDocName = "qryResetMergeFlagsToZero"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Forms.Item("frmRecipients").Requery

Exit_cmdClearFlags_Click:
Exit Sub

Err_cmdClearFlags_Click:
MsgBox Err.Description
Resume Exit_cmdClearFlags_Click

'Resume Microsoft warnings
DoCmd.SetWarnings True
End If
 
This:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Has gone out of fashion. It is now:
DoCmd.RunCommand acCmdSaveRecord

It would be better to put the On Error statement at the beginning. It would be much better to put End If before the error handling routine. I very much doubt that you need DoCmd.Save, because that will save the form, as far as I recall. Nicely indented code is easier to read and maintain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top