Moving Records To Another Table Then Delete

Mar 15, 2007

OK guys, ive done some searching and saw some stuff on this, but everytime I try something I get a INVALID SQL error message. So Im hoping you guys can help out cause Im lost right now.

I have a 2 tables, Training and Schedule. Training contains all the employees training records. Schedule is meant to be a temp table where the supervisors can enter the training and then once completed, can check the COMPLETED checkbox and hit the LOAD TO TRAINING RECORD command button and it moves ONLY the files for that trainee (a combo box) with a completed checkmark to the training table.

Ive tried this code sooooooooo many ways and its giving me a headache. My original way didnt work at all (had a lot of Do..Loop and With Statements, and then someone posted something about Archiving which is the code Ive gone off of now). Any help you guys can off would be awesome!

Heres what I got:

Private Sub cmdLoad_Click()

On Error GoTo Err_Load_Record_Click

UploadHistory

Exit_Load_Record_Click:
Exit Sub

Err_Load_Record_Click:
MsgBox Err.Description
Resume Exit_Load_Record_Click

End Sub

Sub UploadHistory()

Dim DB As Database
Dim WS As Workspace 'Current workspace (for transaction).
Dim strSql As String 'Sql Code.
Dim strMsg As String 'MsgBox message.
Dim bInTrans As Boolean 'Flag that transaction is active.

Set DB = CurrentDb()
Set WS = DBEngine(0)
WS.BeginTrans
bInTrans = True
Set DB = WS(0)

On Error GoTo Err_UploadHistory

'Execute the add.
strSql = "INSERT INTO [Training] " _
& "(TaskNumber, Date, Hours, TrainerLast, TraineeLast, Qualified) " _
& "SELECT " & "Schedule.Task, Schedule.Date, Schedule.Hours, Schedule.Trainer, " _
& "Schedule.Trainee, Schedule.Qualified FROM [Schedule] " _
& "WHERE (((Schedule.Trainee) = " & Me.TraineeCombo & " AND (Schedule.Completed)= 1));"

DoCmd.SetWarnings False
DoCmd.RunSQL strSql
DoCmd.SetWarnings True

'Execute the delete.
strSql = "DELETE FROM [Schedule] WHERE Trainee = " & Me.TraineeCombo & " AND Completed = 1;"

DoCmd.SetWarnings False
DoCmd.RunSQL strSql
DoCmd.SetWarnings True

'Get user confirmation to commit the change.
strMsg = "Upload " & DB.RecordsAffected & " record(s) from " & Me.TraineeCombo & "?"
If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
WS.CommitTrans
bInTrans = False
End If

Exit_UploadHistory:
'Clean up
On Error Resume Next
Set DB = Nothing
If bInTrans Then 'Rollback if the transaction is active.
WS.Rollback
End If
Set WS = Nothing
Exit Sub

Err_UploadHistory:
MsgBox Err.Description, vbExclamation, "Upload failed: Error " & Err.Number
Resume Exit_UploadHistory

End Sub

View Replies


ADVERTISEMENT

Moving Records In The Same Table?

May 22, 2006

Hello there,

Is it possible somehow to move a record in the same table, to different row (in the form)? Or in other words, is it possible manualy adjust the position of records (rows) in a report?

I have a continuous form, where rows are filled with data (e.g. 10 rows ).Then i have report , which looks the same as form (rows, and their order). But sometimes user wants to move certain position (row) up or down, to be it on top or bottom or two places above, or below etc, of row list....is there any easy way to do it? Like some button press, where you could swap position with next record (next row) .....

Or just delete (everything) and fill again from beginning the way he wants...

Thanks!

View 4 Replies View Related

Tables :: Moving Records From One Table To Another

Jan 16, 2014

I have to move records from one table to another.

When we lose a client I need to take them out of my current table and put them in my dropped table.

I don't want to lose my summary info and I want the dropped client to keep it's ID Number which is an identifier.

Seems I can't just copy it from one table to another and then go back and delete it from the Current.

Seems I can't cut from Current and paste into Dropped.

In a perfect world it would be great if my boss could just check a box in Current Table and the record moved to Dropped all by itself!

View 7 Replies View Related

Modules & VBA :: Delete Records From A Table Based On Records In Another

Feb 7, 2014

I have a table InvPrice and Updated Pricing

Need to delete all records from InvPrice that Match UpdatedPricing

InvPrice.StockCode = UpdatedPricing.StockCode
InvPrice.PriceCode = UpdatedPricing.StockCode

I have tried something like this...

Dim dbs As DAO.Database, sql As String, rCount As Integer
Set dbs = CurrentDb
sql = "DELETE * dbo_InvPrice Inner Join (dbo_InvPrice Inner Join UpdatedPricing on dbo_InvPrice.StockCode = UpdatedPricing.StockCode ) ON on dbo_INvPrice.PriceCode = UpdatedPricing.PriceCode "
dbs.Execute sql, dbFailOnError

View 14 Replies View Related

Moving Records From One Table To A New Table?

Apr 10, 2012

1st - Table one, holds around 10,000 recordes, names and phone numbers and basic address information

2nd - Table two which holds all out customer details eg full name and case details and is used by an admin team

What I was hoping to do was have one form designed from table one and when the agent changes a status it moves the record from table one to table two.

View 5 Replies View Related

Delete Records From A Table

Oct 26, 2005

Hi

I'm trying to deleterecords from one table. In the query there are 2 tables both joined. I get an error message come on saying

"Specify The Table Containing The Records you want to Delete"

Below is the query in SQL

DELETE tblStockRequired.StockCode, tblStockRequired.StockQTY, tblStockRequired.OrderNumber
FROM tblOrderCompleted INNER JOIN tblStockRequired ON (tblOrderCompleted.OrderNumber = tblStockRequired.OrderNumber) AND (tblOrderCompleted.StockCode = tblStockRequired.StockCode) AND (tblOrderCompleted.QTY = tblStockRequired.StockQTY);

I want ot delete all records from tblStockRequired which match up with tblOrderCompleted.

Thanks in Advanced

View 2 Replies View Related

Queries :: Delete Records In One Table Dependent On Another Table

Apr 17, 2015

I have a table which lists amendments (amendments history file) which need to take effect of another table (M0070), I can select the records fine and so the sub query looks to be okay but I'm missing something (probably obvious) in the deletion query where by it does only delete the records selected but everything (I know that the asterisk is wrong in the code below but I'm not sure what to replace it with).

At this point I'm trying to delete all records for a specific employee on a specific contract (they can be 1 or more employee records for that individual on a contract - and they could exist on multiple contracts).

DELETE *
FROM M0070
WHERE EXISTS
(SELECT M0070.[Contract No], M0070.[Contract Name], M0070.[Employee No], M0070.Forename, M0070.Surname, M0070.Branch, M0070.[Long Desc], M0070.[Emp Post Start Date], M0070.[Days per week],

[Code] .....

View 3 Replies View Related

Delete Records From Linked DBF Table

Oct 17, 2005

I am having difficulty deleting records in a linked DBF (standalone) table. The table links fine. I can run a delete query and the records appear to be deleted when I view the table from within Access. However, when I view the table outside of Access, the records that I thought were deleted are still there. The only way I can actually delete the records, is to import the table, delete the records and then export the table as a new DBF.

Can someone tell me why deleting from the linked table isn't working?

Thanks,

Sup

View 1 Replies View Related

Delete Records Automatically Frm Table

Jul 26, 2006

How do you have Access delete records automatically from a temp table?

View 1 Replies View Related

Queries :: Specify Table Containing Records That Want To Delete?

Mar 26, 2015

delete Query How do i Specify the table containing the records that I want to delete?

View 1 Replies View Related

Queries :: Delete Records From A Table

May 1, 2015

I have two tables as follows;

Master file:Vessel_master
Vessel_code
Vessel_name

main data table:Main
Vessel_code
container_no
size
Voyage
weight

by using above two table have made a query as follows;

Vessel_name:Vessel_master
Vessel_code:Main
container_no:Main
size:Main
Voyage:Main
weight:Main

Have joined "vessel_code" fields of the both tables by join type 2.

by using the query as data source made a form to edit/update/delete data. the problem is, when delete a record by using the form, it will delete the related data in the master file as well, which i do not want.

View 1 Replies View Related

Delete Duplicate Records In Another Table

Apr 12, 2012

I have two tables that have duplicate order numbers. I would like to compare the first table with the second and then delete the records from the second that match.Can I set this up in a macro and run it every day?

View 2 Replies View Related

Modules & VBA :: Combobox To Delete Records From Table?

Sep 6, 2013

I have a very simple 2010 Access database with only one table which contains a few fields (username, email, phone....)

I have a combobox with unbound controls to search/find users (by the lastname field). The combobox is in the header section which populates the fields (controls?) in subform below.

I have a delete button with some VBA code which allows the user to delete the currently displayed record however when the form refreshes, I end up with two issues:

1: I see #deleted# in the combobox dropdown until the dbase is closed/reopened (it's only typically used by one person at a time.) Compact/Repair doesn't seem necessary, especially since i think it's pretty difficult to do this programatically (?)

2: There are blank rows in the combobox dropdown from where the data used to reside after deleting the record.

I haven't been able to figure out how to remove those blank rows and refresh the combobox to display the remaining records (with the blank rows removed). So I have dozens of blank rows. Me.Requery doesn't seem to work.

My assumption is that the blank rows exist because I'm deleting the content from the combobox's initial creation?

Is there a better way to allow user's to see the list of user's and then be able to select that record and delete it?

If I use a simple search box on a form where people have to type a (last name for example), if it's spelled incorrectly, then nothing would be found.

View 5 Replies View Related

Modules & VBA :: Query To Delete Records From Table

Jul 22, 2015

I have two tables Table1,Table2. I want to delete records from Table1 whose ID= CoventionalID field value from Table2.

Table1 has two fields (ID,PolicyNumber)

Table2 has 5 fields(ID,PolicyNumber,ConventionalID,Conventional PolNo)

The following query doesn't delete anything.

Code:
DELETE *
FROM Table1 WHERE ID=(Select ConventionalID from Table2);

View 3 Replies View Related

Delete Records From One Table Based On Record From Another

Oct 10, 2014

I want to Delete all records from the Table Named "CustomerWiseRotaryTillerRates" (Given Below) if the State in the State Filed in found in the "Customer_Master" Table (attached Herewith). What will be the correct procedure ?

I followed the steps referred in page no. 67 & 68 in the Book "Microsoft Access 2007 Data Analysis" by Mr. Michel Alexender.

Customer Name
State
Product_Code
Product_Name
Price_perunit

TSI Engineering Indutries (P) Ltd.
Assam
P_05
1500_Rotary_Tiller_220_RPM
Rs. 63,722.00

Kishan Krishi Engineering Works
Jharkhand
P_05
1500_Rotary_Tiller_220_RPM
Rs. 62,997.00

TSI Engineering Indutries (P) Ltd.
Assam
P_06
1750_Rotary_Tiller_220_RPM
Rs. 66,663.00

Shri_Tata_Enterprises
Bihar
P_06
1750_Rotary_Tiller_220_RPM
Rs. 65,683.00

View 1 Replies View Related

Tables :: Detect / Delete Duplicate Records In A Table

Apr 22, 2014

I'm wondering if it's possible to create a Query / Macro / VBA or whatever works, to detect the duplicate records in a table and delete them with the push of a command button. Or, even to do this automatically when the database opens using an AutoExec macro or something ?. I'd like for one copy of each record to be left intact in the table.

View 8 Replies View Related

Queries :: Delete Records Based On Criteria In Another Table

Jun 3, 2013

I am trying to create a delete query that, for a given person, deletes records in Table B that do not have a corresponding record in Table A.

Here are the relevant tables:

tblStates holds StateID, StateName, and RegionID (RegionID is a FK to tblRegions).
tblPeopleStates is a junction table between tblPeople and tblStates.

It lists states assigned to people. It has 3 fields: PersonStateID, PersonID, StateID.

tblPeopleRegions is a junction table between tblPeople and tblRegions.

It lists regions assigned to people. It has 3 fields: PersonRegionID, PersonID, RegionID.

For a given PersonID, I need to delete records (i.e., states) in tblPeopleStates whose RegionID is *not* in tblPeopleRegions.

For example, pretend that tblStates shows that State IDs 1, 5, and 6 are all in Region ID (i.e., all have a RegionID = 10).

If Joe (PersonID = 200) has StateIDs 1, 5, and 6 in tblPeopleStates, but doesn't have a record for RegionID = 10 in tblPeopleRegions, I need to delete his three records in tblPeopleStates (i.e., the ones where StateID = 1, 5, and 6).

PersonID will be found on [Forms]![frmMain]![subform1].[Form]![subform2].Form]![PersonID]

View 8 Replies View Related

Modules & VBA :: Delete Records From A Table Using Controls On A Subform

Jun 20, 2013

I have a sub form that allows users to add staff to a project team, once added it populates a table which updates the subform showing the selected employee. I am trying to enable a delete function that allows users to remove an employee from the project team in the subform showing selected staff. Here is the code I have so far, but it doesn't work;

Code:
Private Sub Command4_Click()
Dim dbs As Database
Dim rs As Recordset
Dim sqlstr As String
Set dbs = CurrentDb
sqlstr = "DELETE tbl_CapexStaff.* FROM tbl_CapexStaff WHERE CAP_ID = Forms!frm_Switchboard.CAP_Live"
dbs.Execute (sqlstr)
End Sub

View 4 Replies View Related

Queries :: Delete Duplicated Records Without Having To Make A New Table?

Apr 17, 2013

How do I delete duplicated records without having to make a new table? I would like the records deleted from the original table.

View 13 Replies View Related

Delete Records That Match Multiple Criteria From Second Table

Jan 23, 2012

I would like to create a query that will delete records that match several fields from another table. This is complicated by the fact that one of the fields will be in one of 3 columns.I have attached a test database (no real details), all Sheet2 entries need to be deleted from Sheet1.

What I need to do is delete records that have the same 'Surname' and 'DPS' value but also the same 'Line5' value from Sheet2 in 'Line3' or 'Line4' or 'Line5' in Sheet1.The 'Surname' and 'DPS' are no problem, it's the variable position of the third field. I think I could do it in three separate queries but it would definitely be better in one.

View 5 Replies View Related

Forms :: Add / Edit And Delete Records From A Table Based On Combo

Dec 12, 2013

I have a form to add, edit, and delete Records from a table. I am using the following VBA

Private Sub cmdEdit_Click()
If Not (Me.frmlEmpDetailsSub.Form.Recordset.EOF And Me.frmlEmpDetailsSub.Form.Recordset.BOF) Then
With Me.frmlEmpDetailsSub.Form.Recordset
Me.txtAddEditname = .Fields("Name")
Me.cboRoster = .Fields("Roster")
Me.cboPermFctn = .Fields("PermFctn")
End With
End If
End Sub

Instead of referring to the Subform to load the data i would like to refer to a combobox:

cboSearchName

Its not an issue but This Combobox contains 5 columns...

View 2 Replies View Related

Modules & VBA :: Reset Autonumber Each Time Delete / Append Records In A Table?

Oct 25, 2013

I need to reset the autonumber each time I delete/append records in a table. Best way?

View 5 Replies View Related

Delete Records From One Table That Appear In Another Table

Apr 27, 2006

Hi all,

Quick question...

I have a master client table and a table of clients that have ordered from us, so don't want to be called again.

I want to delete the clients record from the master table by comparing the two tables and sayi that 'everytime you find a phone number from the 'ordered' table that exists in the master table, delete the record from the master table.

That way I will end up with a master table of clients who haven't placed an order.

Could anyone tell me the quey to run that could do that.

Thanks in advance - Lee

View 4 Replies View Related

Moving Records

Mar 6, 2005

I would like a button on my form that will move a record from one table to another. Can anyone tell me how to do this

View 2 Replies View Related

Moving Old Records.

Oct 25, 2005

hiya!

i have a database that holds details of calls that have been answered on the phone concerning problems with computers.
details that are recorded are caller name, and date of call etc...

however, i want to know if there is a way that i can move all calls recorded BEFORE the present date to another table ( say a "past calls")..?

is there a button that i can put on my database that will run a function and move all calls recorded before the present date to another seperate table..?

thanks everyone!
johnny
:)

View 1 Replies View Related

Moving Records

Jun 27, 2005

Could someone assist me in getting code that allows me to move a record from one table to another when the user clicks a button.

Thanks

View 13 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved