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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete first record in a subform 1

Status
Not open for further replies.

JamesMcG

IS-IT--Management
Jun 16, 2000
31
0
0
IE
I have a form that uses a combo box and subform. The subform is controlled by the combo box.

When a value is selected in the combo box it displays 1 record in the subform. I was to be able to delete this record using visual basic. I have tried the following type of thing:

[forms]![form_name]![subform_name.form(0)].delete

I know this is wrong because it does not work, can anybody point me in the right direction please?

Thanks in advance,
James [sig][/sig]
 
try this ...

DoCmd.GoToRecord acDataForm, 1 ' Zero based numbering ?
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


...have fun ! :p [sig]<p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br> [/sig]
 
this is what I am using

DoCmd.GoToRecord acDataForm, &quot;deletesubform&quot;, acFirst
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

it still wont work though, it keeps giving me an error saying it cant find the subform &quot;deletesubform&quot;, but it is open on the form and is named correctly.

Is there a different way to access subforms?

Thanks for your help,
James [sig][/sig]
 
This,
DoCmd.GoToRecord acDataForm, &quot;deletesubform&quot;, acFirst
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
...would have to be in the form where the deletion is to take place in order to work. So perhaps instead;

here is a more straight forward way of accomplishing the delete from the main form. This assumes the use of an autonumber field in the sub form's record source.



DoCmd.SetWarnings False 'hide dialogs from user
[red]DoCmd.RunSQL &quot;DELETE * FROM [tblUsedBySubform]
WHERE [ID] = (SELECT TOP 1 [tblUsedBySubform]
.[ID] FROM [tblUsedBySubform] ORDER BY [tblUsedBySubform]
.[ID]);[/red]
DoCmd.SetWarnings True ' restore dialog display

Forms![frmMainForm]![frmSubForm].Requery
Forms![frmMainForm]![frmSubForm].Refresh
;-) [sig]<p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br> [/sig]
 
Hello,

I'm having a similiar issue. I have a button on my subform which I'd like to delete a group of selected records on the subform. The problem is no matter how many I select on the subform it only deletes the first one.

The code Access places in there is as follows:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

This tells Access to select the record (whichever has the arrow next to it, typically the first) and delete it. This ignores any other selected records.

What I need to know is the best way to grab the selected records and then delete them using VB code.

Thanks in advance for any help.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top