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

Move and Delete Records from Tables

Status
Not open for further replies.

rj51cxa

Technical User
Mar 16, 2006
216
GB
I have two queries which run consecutively from a command button. The first query, which opens with a message box asking me to select the months in question, copies the selected records from TblTranasctions to TblTranactions_Old. The second query, which opens with the same message box, deletes the selected records from TblTransactions.

The two codes are as follows:

QryMoveData:
Code:
INSERT INTO TblTransactions_Old ( ShtMonth, Type, Details, Amount, [Date] )
SELECT TblTransactions.ShtMonth, TblTransactions.Type, TblTransactions.Details, TblTransactions.Amount, TblTransactions.Date
FROM TblTransactions
WHERE (((IIf([ShtMonth]="Jan",1,IIf([ShtMonth]="Feb",2,IIf([ShtMonth]="Mar",3,IIf([ShtMonth]="Apr",4,IIf([ShtMonth]="May",5,IIf([ShtMonth]="Jun",6,IIf([ShtMonth]="Jul",7,IIf([ShtMonth]="Aug",8,IIf([ShtMonth]="Sep",9,IIf([ShtMonth]="Oct",10,IIf([ShtMonth]="Nov",11,IIf([ShtMonth]="Dec",12,""))))))))))))) Between [Enter Month 1] And [Enter Month 2]))
ORDER BY TblTransactions.Date;

QryDeleteData:
Code:
DELETE TblTransactions.TransactionNumber, TblTransactions.ShtMonth, TblTransactions.Type, TblTransactions.Details, TblTransactions.Amount, TblTransactions.Date, TblTransactions.Statement, TblTransactions.Notes, IIf([ShtMonth]="Jan",1,IIf([ShtMonth]="Feb",2,IIf([ShtMonth]="Mar",3,IIf([ShtMonth]="Apr",4,IIf([ShtMonth]="May",5,IIf([ShtMonth]="Jun",6,IIf([ShtMonth]="Jul",7,IIf([ShtMonth]="Aug",8,IIf([ShtMonth]="Sep",9,IIf([ShtMonth]="Oct",10,IIf([ShtMonth]="Nov",11,IIf([ShtMonth]="Dec",12,"")))))))))))) AS Expr1
FROM TblTransactions
WHERE (((IIf([ShtMonth]="Jan",1,IIf([ShtMonth]="Feb",2,IIf([ShtMonth]="Mar",3,IIf([ShtMonth]="Apr",4,IIf([ShtMonth]="May",5,IIf([ShtMonth]="Jun",6,IIf([ShtMonth]="Jul",7,IIf([ShtMonth]="Aug",8,IIf([ShtMonth]="Sep",9,IIf([ShtMonth]="Oct",10,IIf([ShtMonth]="Nov",11,IIf([ShtMonth]="Dec",12,""))))))))))))) Between [Enter Month 1] And [Enter Month 2]));

Can anyone please tell me if there is a way of combining these two queries into one piece of code so that I only have to enter the months to copy and delete once.

I would also like to know if the whole of the final code can be run as an event from a command button rather than having two queries which are run from the command button.

Best Regards
John
 
Can anyone please tell me if there is a way of combining these two queries into one piece of code so that I only have to enter the months to copy and delete once.
No, but you can add two text boxes to your form and reference the form values in each query. e.g.
Code:
INSERT INTO TblTransactions_Old ( ShtMonth, Type, Details, Amount, [Date] )
...
WHERE (((IIf([ShtMonth]="Jan",1,IIf([ShtMonth]="Feb",2,IIf([ShtMonth]="Mar",3,IIf([ShtMonth]="Apr",4,IIf([ShtMonth]="May",5,IIf([ShtMonth]="Jun",6,IIf([ShtMonth]="Jul",7,IIf([ShtMonth]="Aug",8,IIf([ShtMonth]="Sep",9,IIf([ShtMonth]="Oct",10,IIf([ShtMonth]="Nov",11,IIf([ShtMonth]="Dec",12,""))))))))))))) Between [b][Forms]![frmSelectMonth]![txtMonth1].[Value] And [Forms]![frmSelectMonth]![txtMonth2].[Value]))[/b]
...

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thanks Traingamer, I'll give that a try.

Best Regards
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top