Sql insert into

SergioRocha

Registered User.
Local time
Today, 10:52
Joined
Dec 7, 2008
Messages
15
Hi,

I have 3 tables: Movimentos, Compras, Vendas

The table Movimentos stores all the data about buying and selling stocks.
When i want to sell some stock, my code do the following:
1- Selects the stocks i want from Movimentos and copy all the records to table Compras and delete them from table Movimentos;
2 - It make some calculations in table Compras and changes the values;
3 - Write some records (one or more) in table Vendas;
4 - It copies all the calculated record in table Compras and Vendas to Table Movimentos;
5 - Deletes all records in table Compras and Vendas.

I wrote the code but i have some problems with the table's key fields.

Code:
Private Sub Comando29_Click()

Dim db As DAO.Database
Dim rst_mov, rst_compr, rst_vend As Recordset
Dim strNome As String
Dim ncompr, nvend, i, j As Integer

strNome = Me.Nome.Value

Set db = CurrentDb

db.Execute "DELETE * FROM Movimentos WHERE Movimentos.Nome= '" & strNome & "' And Movimentos.Operacao = 'Compra' And Movimentos.Quantidade_Rest>0"

db.Execute "INSERT INTO Movimentos SELECT Nome,Data,Operacao,Quantidade,Quantidade_Rest,Valor_Unitario,Comissoes,Validar,Total,Valias FROM Compras"

db.Execute "INSERT INTO Movimentos SELECT Nome,Data,Operacao,Quantidade,Quantidade_Rest,Valor_Unitario,Comissoes,Validar,Total,Valias FROM Vendas"

db.Execute "DELETE * FROM Compras"
db.Execute "DELETE * FROM Vendas"

Me.Compras.Requery
Me.Vendas_subformulário.Requery
Me.Texto0.Value = ""
Me.Texto2.Value = ""
Me.Texto6.Value = ""
Me.Texto8.Value = ""

End Sub

Any suggestions!?

Thank you for your time...
 

Users who are viewing this thread

Back
Top Bottom