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. - Private Sub cmdDeleteRecord_Click()
-
On Error GoTo Err_cmdDeleteRecord_Click
-
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
-
-
DoCmd.RunCommand acCmdDeleteRecord
-
RunCommand acCmdSelectRecord
-
Exit_cmdDeleteRecord_Click:
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
Exit Sub
-
-
Err_cmdDeleteRecord_Click:
-
If Err.Number <> 3021 Then
-
MsgBox Err.Description
-
End If
-
' If Err = 3021 Then 'No current record
-
' MsgBox "Deletion Successful"
-
-
'Exit Sub
-
' Else
-
' MsgBox Err.Description
-
' Resume Exit_cmdDeleteRecord_Click
-
'End If
-
-
Resume Exit_cmdDeleteRecord_Click
-
-
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
15 5022
Hi man
I think you have to put all your data in rercodset and check it. -
-
-
dim mysql as string
-
dim db as database
-
dim rs as recordset
-
-
mysq = "select * from [yourtable] ;"
-
Set db = CurrentDb()
-
Set rs = db2.OpenRecordset(mysq2, dbOpenDynaset)
-
rs.movefirst
-
While Not (rs.BOF Or rs.EOF)
-
if(SerialNumber="")then
-
rs.delete
-
endif
-
rs.MoveNext
-
Wend
-
docmd.requery
-
regards
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
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.
You don't have the reference set for Microsoft DAO Object Library.
Thanks Don,
How do I get it?
Kevin
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
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
Have you tried deleting with a simple SQL command like so? -
DoCmd.SetWarnings False
-
strSQL = "DELETE FROM yourtable WHERE yourFieldName IS NULL"
-
DoCmd.RunSQL (strSQL)
-
DoCmd.SetWarnings True
-
cheers,
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
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.
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
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.
Thanks Don,
Can you give me the code for this?
Kevin
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 -
Private Sub YourButton_Click()
-
On Error GoTo ErrPoint
-
-
Dim FormPart as string, FormSer as string, FormQty as integer
-
FormPart = me.Control1
-
FormSer = me.Control2
-
FormQty = me.Control3
-
-
Dim db as dao.database, rs as dao.recordset
-
set db = currentdb()
-
set rs = db.openrecordset("YourTable")
-
rs.movefirst
-
Do While Not rs.eof and FormQty > 0
-
If rs!Field1 = FormPart and rs!Field2 = FormSer then
-
rs.delete
-
FormQty = FormQty - 1
-
End If
-
rs.movenext
-
Loop
-
If rs.eof and FormQty > 0 then
-
msgbox "You have attempted to delete more records than are available" _
-
& vbcrlf & (me.Control3 - FormQty) & " records have been deleted"
-
Else
-
msgobx me.Control3 & " records have been deleted"
-
End If
-
rs.close
-
set rs = nothing
-
set db = nothing
-
-
ExitPoint:
-
Exit Sub
-
-
ErrPoint:
-
Msgbox err.number & " " & err.description
-
resume ExitPoint
-
-
End Sub
-
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 -
Private Sub YourButton_Click()
-
On Error GoTo ErrPoint
-
-
Dim FormPart as string, FormSer as string, FormQty as integer
-
FormPart = me.Control1
-
FormSer = me.Control2
-
FormQty = me.Control3
-
-
Dim db as dao.database, rs as dao.recordset
-
set db = currentdb()
-
set rs = db.openrecordset("YourTable")
-
rs.movefirst
-
Do While Not rs.eof and FormQty > 0
-
If rs!Field1 = FormPart and rs!Field2 = FormSer then
-
rs.delete
-
FormQty = FormQty - 1
-
End If
-
rs.movenext
-
Loop
-
If rs.eof and FormQty > 0 then
-
msgbox "You have attempted to delete more records than are available" _
-
& vbcrlf & (me.Control3 - FormQty) & " records have been deleted"
-
Else
-
msgobx me.Control3 & " records have been deleted"
-
End If
-
rs.close
-
set rs = nothing
-
set db = nothing
-
-
ExitPoint:
-
Exit Sub
-
-
ErrPoint:
-
Msgbox err.number & " " & err.description
-
resume ExitPoint
-
-
End Sub
-
Thanks Don for all of your help!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |