dbTalk Databases Forums  

Processing Selected Records in Datasheet

comp.databases.ms-access comp.databases.ms-access


Discuss Processing Selected Records in Datasheet in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
freddy007
 
Posts: n/a

Default Processing Selected Records in Datasheet - 04-18-2009 , 06:55 PM






I'd like to allow a user to select several non-contiguous rows in a
datasheet form and then click a button to delete these records from a
table, or perform some other action on them (via a vba routine). I
tried adding an unbound checkbox to the form, but when it is checked,
they all get checked. Does someone know a good way to do this?
thanks
-John

Reply With Quote
  #2  
Old   
tina
 
Posts: n/a

Default Re: Processing Selected Records in Datasheet - 04-18-2009 , 09:11 PM






the checkbox idea will work, but only if the checkbox is bound to a field in
the form's underlying recordset. you can do this by setting up a temp table
(i usually put the table in a temp database located on the user's PC, and
link it to the frontend db; that takes care of the bloating issue associated
with adding/deleting records over and over, as well as the multi-user
conflict issue). the table needs only two fields: a field to hold the
primary key value from the data table, and a Yes/No field. in the form's
RecordSource, link the temp table to the data table on the primary key
fields in each, using a LEFT JOIN from the data table to the temp table.
bind the Yes/No field to a checkbox in the form.

write a query to delete all records from the data table WHERE the primary
key = the primary key field of the temp table. write another query to delete
all records from the temp table.

add a button to the form to run the queries, for example

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDeleteDataRecords"
DoCmd.OpenQuery "qryDeleteTempRecords"
DoCmd.SetWarnings True
Me.Requery

so the user can checkmark the records to be deleted, click the button, and
the code will delete those records, empty the temp table, and then requery
the form so the deleted records "disappear".

hth


"freddy007" <jojo (AT) ebold (DOT) com> wrote

Quote:
I'd like to allow a user to select several non-contiguous rows in a
datasheet form and then click a button to delete these records from a
table, or perform some other action on them (via a vba routine). I
tried adding an unbound checkbox to the form, but when it is checked,
they all get checked. Does someone know a good way to do this?
thanks
-John



Reply With Quote
  #3  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Processing Selected Records in Datasheet - 04-18-2009 , 09:36 PM



freddy007 wrote:

Quote:
I'd like to allow a user to select several non-contiguous rows in a
datasheet form and then click a button to delete these records from a
table, or perform some other action on them (via a vba routine). I
tried adding an unbound checkbox to the form, but when it is checked,
they all get checked. Does someone know a good way to do this?

I usually do the same thing Tina suggested, but if the
form's recorset is relatively small (<100 records) you might
want to check out Albert's clever idea in his Multi Select
example database at
http://www.members.shaw.ca/AlbertKal.../msaccess.html

--
Marsh


Reply With Quote
  #4  
Old   
tina
 
Posts: n/a

Default Re: Processing Selected Records in Datasheet - 04-18-2009 , 10:04 PM



okay, let me amend my opening statement: the checkbox idea will work if you
bind the control to a field in the form's underlying recordset, OR if you
store the selection in a collection as demonstrated in MVP Albert Kallal's
cool code, found at the link provided in Marsh's post to this thread. thanks
for the link, Marsh; as always, Albert finds the simplest way to do things!



"tina" <nospam (AT) address (DOT) com> wrote

Quote:
the checkbox idea will work, but only if the checkbox is bound to a field
in
the form's underlying recordset. you can do this by setting up a temp
table
(i usually put the table in a temp database located on the user's PC, and
link it to the frontend db; that takes care of the bloating issue
associated
with adding/deleting records over and over, as well as the multi-user
conflict issue). the table needs only two fields: a field to hold the
primary key value from the data table, and a Yes/No field. in the form's
RecordSource, link the temp table to the data table on the primary key
fields in each, using a LEFT JOIN from the data table to the temp table.
bind the Yes/No field to a checkbox in the form.

write a query to delete all records from the data table WHERE the primary
key = the primary key field of the temp table. write another query to
delete
all records from the temp table.

add a button to the form to run the queries, for example

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDeleteDataRecords"
DoCmd.OpenQuery "qryDeleteTempRecords"
DoCmd.SetWarnings True
Me.Requery

so the user can checkmark the records to be deleted, click the button, and
the code will delete those records, empty the temp table, and then requery
the form so the deleted records "disappear".

hth


"freddy007" <jojo (AT) ebold (DOT) com> wrote in message
news:535ceb58-98bb-4c34-bf8d-9ea71b5d67ea (AT) y6g2000prf (DOT) googlegroups.com...
I'd like to allow a user to select several non-contiguous rows in a
datasheet form and then click a button to delete these records from a
table, or perform some other action on them (via a vba routine). I
tried adding an unbound checkbox to the form, but when it is checked,
they all get checked. Does someone know a good way to do this?
thanks
-John





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.