Hello:
I have a problem with some code I am working with. I have a table with collections of products, and other table with the products. What I have to do is: when somebody buys a collection the program must take all the products belonging to that collection and insert them in another table.
To do that I use an array of querydefs (because I don't know how many products are gonna be in each collection) and I make a querdef for each product. The code is working fine, but as I use the CreateQueryDef option, all the querys I create must be deleted after they are executed (in order to use this function some other time). The question is:
Is it possible to have an array of queries and execute them without been the queries created at the database (actually creating them in memory), and afterwards "kill" the array?
2. Otherwise, the only choice I have is to make a function and delete the queries I created one by one?
I put here the code. I hope it is useful for someone to help me!
Thanks in advance!
Set WSfroga = DBEngine.Workspaces(0)
WSfroga.BeginTrans
Set rst = CurrentDb.OpenRecordset("SELECT * FROM Collection WHERE Collection.id = " & Me.id)
While Not rst.EOF
kontsulta = "INSERT INTO Warehouse(id,kostua, Data, Arrazoia, Kopurua) VALUES (" _
& rst!id & ",'" & kostua & "', '" & data & "', " & Arrazoia & "," & Kopurua & "
;"
Set qdfroga(i) = CurrentDb.CreateQueryDef(i, kontsulta)
qdfroga(i).Execute
i = i + 1
rst.MoveNext
Wend
If MsgBox("Are you sure you want to append this rows?", vbYesNo) = vbYes Then
WSfroga.CommitTrans
Else
WSfroga.Rollback
End If
I have a problem with some code I am working with. I have a table with collections of products, and other table with the products. What I have to do is: when somebody buys a collection the program must take all the products belonging to that collection and insert them in another table.
To do that I use an array of querydefs (because I don't know how many products are gonna be in each collection) and I make a querdef for each product. The code is working fine, but as I use the CreateQueryDef option, all the querys I create must be deleted after they are executed (in order to use this function some other time). The question is:
Is it possible to have an array of queries and execute them without been the queries created at the database (actually creating them in memory), and afterwards "kill" the array?
2. Otherwise, the only choice I have is to make a function and delete the queries I created one by one?
I put here the code. I hope it is useful for someone to help me!
Thanks in advance!
Set WSfroga = DBEngine.Workspaces(0)
WSfroga.BeginTrans
Set rst = CurrentDb.OpenRecordset("SELECT * FROM Collection WHERE Collection.id = " & Me.id)
While Not rst.EOF
kontsulta = "INSERT INTO Warehouse(id,kostua, Data, Arrazoia, Kopurua) VALUES (" _
& rst!id & ",'" & kostua & "', '" & data & "', " & Arrazoia & "," & Kopurua & "
Set qdfroga(i) = CurrentDb.CreateQueryDef(i, kontsulta)
qdfroga(i).Execute
i = i + 1
rst.MoveNext
Wend
If MsgBox("Are you sure you want to append this rows?", vbYesNo) = vbYes Then
WSfroga.CommitTrans
Else
WSfroga.Rollback
End If