473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Delete Multiple Records On A Form

I have an existing inventory database that I'm trying to make changes to. The database only has 1 table with the following fields:

PartNumber
ItemDescription
Category
Location
Owner
SerialNumber.

Currently I'm using the delete button to delete a single item.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDeleteRecord_Click()
  2. On Error GoTo Err_cmdDeleteRecord_Click
  3.     'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  4.     'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  5.  
  6.      DoCmd.RunCommand acCmdDeleteRecord
  7.     RunCommand acCmdSelectRecord
  8. Exit_cmdDeleteRecord_Click:
  9. DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  10.             Exit Sub
  11.  
  12. Err_cmdDeleteRecord_Click:
  13.  If Err.Number <> 3021 Then
  14. MsgBox Err.Description
  15. End If
  16.    ' If Err = 3021 Then 'No current record
  17.    ' MsgBox "Deletion Successful"
  18.  
  19. 'Exit Sub
  20.  '   Else
  21.   '  MsgBox Err.Description
  22.    ' Resume Exit_cmdDeleteRecord_Click
  23. 'End If
  24.  
  25.     Resume Exit_cmdDeleteRecord_Click
  26.  
  27. End Sub
However this is not really efficient if I have to delete 300 disk drives. I have the multiple add working and I'd like to put in a delete. I'd like the delete to first search the 'SerialNumber' field and if it's blank then allow the delete multiple copies.

Is this possible?


Thanks,

Kevin
Oct 14 '08 #1
15 5022
wassimdaccache
222 100+
Hi man

I think you have to put all your data in rercodset and check it.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. dim mysql as string 
  4. dim db as database
  5. dim rs as recordset 
  6.  
  7.  mysq = "select * from [yourtable] ;"
  8. Set db = CurrentDb()
  9. Set rs = db2.OpenRecordset(mysq2, dbOpenDynaset)
  10. rs.movefirst
  11. While Not (rs.BOF Or rs.EOF) 
  12. if(SerialNumber="")then 
  13. rs.delete
  14. endif 
  15. rs.MoveNext
  16. Wend  
  17. docmd.requery 
  18.  
regards
Oct 14 '08 #2
Hi,

Thanks for the fast response. I put the code in but I get a compile error at 'Dim db As Database' (Compile error: user-defined type not defined). I checked ?CurrentProject.Connection and it came back with Provider=Microsoft.ACE.OLEDB.12.0. I also tried DAO.Database and DAO.Recordset but I still get the same error.

Thanks,

Kevin
Oct 14 '08 #3
DonRayner
489 Expert 256MB
Hi,

Thanks for the fast response. I put the code in but I get a compile error at 'Dim db As Database' (Compile error: user-defined type not defined). I checked ?CurrentProject.Connection and it came back with Provider=Microsoft.ACE.OLEDB.12.0. I also tried DAO.Database and DAO.Recordset but I still get the same error.

Thanks,

Kevin
You don't have the reference set for Microsoft DAO Object Library.
Oct 14 '08 #4
You don't have the reference set for Microsoft DAO Object Library.

Thanks Don,

How do I get it?

Kevin
Oct 14 '08 #5
DonRayner
489 Expert 256MB
Thanks Don,

How do I get it?

Kevin
When you are in the VBA programing screen of any module select Tools - References on the menu bar. Look for the Microsoft DAO..... and select the checkbox next to it
Oct 14 '08 #6
Thanks for your help all,

I was wondering if my Delete can work like my Copy,

Private Sub cmdMultiCopy_Click()
Dim Copies as Integer

If Me.Dirty Then Me.Dirty = False

If Not IsNull(Me.NumberCopies) then
Copies = Me.NumberCopies
Else
Copies = 1
End If

For I = 1 To Copies
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPaste
Next I

End Sub


My copy reads the 'NumberCopies' text box on the form. Then takes the integer and copies that many records to the database. Is there any way to get the delete to do the same. I have a text box on my form 'NumberDeleted'.

Thanks,

Kevin
Oct 15 '08 #7
mshmyob
904 Expert 512MB
Have you tried deleting with a simple SQL command like so?

Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False 
  2. strSQL = "DELETE FROM yourtable WHERE yourFieldName IS NULL"
  3. DoCmd.RunSQL (strSQL)
  4. DoCmd.SetWarnings True 
  5.  
cheers,
Oct 15 '08 #8
Thanks for everybody's help,

but I'm using an inventory system. On the form there is a list of all the items in the database. I can not just delete all items without a serial number. The user selects a record from the list, and the form brings up the record and all of it's fields. I'd like the user to input a qty from a text box and the Delete button read that qty and then delete. Here is what I have so far.

Asset = Asset - Data

criteria = "! isnull(serial) and asset=" & asset

if ! isnull(user) then
criteria = criteria & " and user=" & user-datea
end if

for i = 1 to copies

rs.findfirst criteria

if rs.NoMatch then
msgbox "Deleted only" & i-1 & " records!"
fulldelete=false
exit for
end if

rs.delete

next i

if ! fulldelete msgbox copies & " Records Deleted!"

I'm not sure what the syntax for the criteria should be.

Thanks,

Kevin
Oct 15 '08 #9
DonRayner
489 Expert 256MB
Thanks for everybody's help,

but I'm using an inventory system. On the form there is a list of all the items in the database. I can not just delete all items without a serial number. The user selects a record from the list, and the form brings up the record and all of it's fields. I'd like the user to input a qty from a text box and the Delete button read that qty and then delete. Here is what I have so far.

Asset = Asset - Data

criteria = "! isnull(serial) and asset=" & asset

if ! isnull(user) then
criteria = criteria & " and user=" & user-datea
end if

for i = 1 to copies

rs.findfirst criteria

if rs.NoMatch then
msgbox "Deleted only" & i-1 & " records!"
fulldelete=false
exit for
end if

rs.delete

next i

if ! fulldelete msgbox copies & " Records Deleted!"

I'm not sure what the syntax for the criteria should be.

Thanks,

Kevin
I'm not realy sure what you're after here. It sounds like you bring up the record for and item which has a certain quanity and you want to adjust that quanity by the ammount that is entered into a text box.
Oct 15 '08 #10
Hi Don,

I am pulling up a record, but each record is a quantity of 1 because most of my records have serial numbers. However we do have parts that do not have serial numbers. Each record represents 1 item in inventory. I have a text box on my form where the user can enter a qty to delete. So first the user selects the item (item without a serial number), then enters a qty in a text box, then hits the delete button on the form. The code I left there is my pseudo code.

Thanks,

Kevin
Oct 15 '08 #11
DonRayner
489 Expert 256MB
Hi Don,

I am pulling up a record, but each record is a quantity of 1 because most of my records have serial numbers. However we do have parts that do not have serial numbers. Each record represents 1 item in inventory. I have a text box on my form where the user can enter a qty to delete. So first the user selects the item (item without a serial number), then enters a qty in a text box, then hits the delete button on the form. The code I left there is my pseudo code.

Thanks,

Kevin
Ok, I get it now. So if you have 50 widgets without serial numbers, the widgets are in your db 50 times. You want to be able to bring up the record for 1 widget and using that delete x number of widgets from the db. :)

So the criteria in your code should be to match part number and serial number, step through the recordset until you have matched and deleted x number of records then exit the code.
Oct 16 '08 #12
Thanks Don,

Can you give me the code for this?

Kevin
Oct 16 '08 #13
DonRayner
489 Expert 256MB
Thanks Don,

Can you give me the code for this?

Kevin
Try this Kevin

Replace Field1 with the name of your Part or ID field
Replace Field2 with the name of your Serial Number field
Replace YourTable with the name of your table containg the records
Change Control1 to name of part or id control
Change Contorl2 to name of serial number control
Change Control 3 to name of delete quanity control
Change YourButton to the name of your delete button

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButton_Click()
  2. On Error GoTo ErrPoint
  3.  
  4. Dim FormPart as string, FormSer as string, FormQty as integer
  5. FormPart = me.Control1
  6. FormSer = me.Control2
  7. FormQty = me.Control3
  8.  
  9. Dim db as dao.database, rs as dao.recordset
  10. set db = currentdb()
  11. set rs = db.openrecordset("YourTable")
  12. rs.movefirst
  13. Do While Not rs.eof and FormQty > 0
  14.     If rs!Field1 = FormPart and rs!Field2 = FormSer then
  15.          rs.delete
  16.          FormQty = FormQty - 1
  17.     End If
  18.     rs.movenext
  19. Loop
  20. If rs.eof and FormQty > 0 then
  21.     msgbox "You have attempted to delete more records than are available" _
  22.     & vbcrlf & (me.Control3 - FormQty) & " records have been deleted"
  23. Else
  24.     msgobx me.Control3 & " records have been deleted"
  25. End If
  26. rs.close
  27. set rs = nothing
  28. set db = nothing
  29.  
  30. ExitPoint:
  31.     Exit Sub
  32.  
  33. ErrPoint:
  34.     Msgbox err.number & " " & err.description
  35.     resume ExitPoint
  36.  
  37. End Sub
  38.  
Oct 16 '08 #14
Try this Kevin

Replace Field1 with the name of your Part or ID field
Replace Field2 with the name of your Serial Number field
Replace YourTable with the name of your table containg the records
Change Control1 to name of part or id control
Change Contorl2 to name of serial number control
Change Control 3 to name of delete quanity control
Change YourButton to the name of your delete button

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourButton_Click()
  2. On Error GoTo ErrPoint
  3.  
  4. Dim FormPart as string, FormSer as string, FormQty as integer
  5. FormPart = me.Control1
  6. FormSer = me.Control2
  7. FormQty = me.Control3
  8.  
  9. Dim db as dao.database, rs as dao.recordset
  10. set db = currentdb()
  11. set rs = db.openrecordset("YourTable")
  12. rs.movefirst
  13. Do While Not rs.eof and FormQty > 0
  14.     If rs!Field1 = FormPart and rs!Field2 = FormSer then
  15.          rs.delete
  16.          FormQty = FormQty - 1
  17.     End If
  18.     rs.movenext
  19. Loop
  20. If rs.eof and FormQty > 0 then
  21.     msgbox "You have attempted to delete more records than are available" _
  22.     & vbcrlf & (me.Control3 - FormQty) & " records have been deleted"
  23. Else
  24.     msgobx me.Control3 & " records have been deleted"
  25. End If
  26. rs.close
  27. set rs = nothing
  28. set db = nothing
  29.  
  30. ExitPoint:
  31.     Exit Sub
  32.  
  33. ErrPoint:
  34.     Msgbox err.number & " " & err.description
  35.     resume ExitPoint
  36.  
  37. End Sub
  38.  

Thanks Don for all of your help!
Oct 20 '08 #15
DonRayner
489 Expert 256MB
Glad I could help

Don
Oct 20 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
2
by: jim Bob | last post by:
Hi, I have a form with a list box that shows the contents of a table and managed to create an add record button with the wizard. (DoCmd.GoToRecord , , acNewRec) Now i want to make a delete...
3
by: Jeff | last post by:
In a subform I have a simple SQL statement that links an order details table to a product table. The form is used to enter order details. Most fields are obviously from the details table, with only...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
5
by: Gareith Stanley | last post by:
Hi there I have an access form that allows the user to browse records (< and > buttons) sorted by another field within that table (eg, all entries under a staff group, all entries under a student...
1
by: Nettle | last post by:
Purpose: This is a Distribution List database. Function: Users create many different email distribution lists, tailoring each to fit their specific needs Wanted: Users can combine...
1
by: chocciies | last post by:
Hi! I want to delete multiple record via checkboxes. However, with no success. Is there sthg wrong with the value of my checkbox? Your help will be greatly appreciated. Thanks! <form...
1
by: busterbaxter | last post by:
Hi All, I have an existing inventory database that I'm trying to make changes to. The database only has 1 table with the following fields: PartNumber ItemDescription Category Location Owner...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.