This topic is locked

INSERT INTO Statement Help

9/9/2008 5:21:55 PM
ASPRunnerPro General questions
M
mccreelake author

Hi,
I need to run an insert into statement when users view a record in a table. The INSERT statement needs to insert multiple records into another table based on values for the record they choose to view. Additionally, a couple of the fields on the records that are being inserted need to be equal to values from the record the users select to view. Basically, I need to run an INSERT statement with both SELECT values inserted into the table and some explicit values declared by the VIEW page the users go to. Here is my code below:

Sub ViewOnLoad()
Set VALUE1 = dict("GroupEventID")

Set VALUE2 = dict("Events_EventID")

Set VALUE3 = dict("Groups_GroupID")
strSQLInsert = "INSERT INTO Events_Clients_GrpAff (Events_Clients_GrpAff.[Type], AttnPeriod, Groups_Clients_GroupClientID, Groups_Events_GroupEventID, OrigEventID) "

strSQLInsert = strSQLInsert & "SELECT (Groups_Clients.[Type], Groups.AttnPeriod, Groups_Clients.GroupClientID,"

strSQLInsert = strSQLInsert & VALUE1 & ", "

strSQLInsert = strSQLInsert & VALUE2 & ")"

strSQLInsert = strSQLInsert & "FROM Groups_Clients INNER JOIN Groups ON Groups_Clients.Groups_GroupID=Groups.GroupID "

strSQLInsert = strSQLInsert & "WHERE Groups_Clients.[Type]='Student' AND Groups_Clients.Status='Active' AND Groups_Clients.Groups_GroupID="

strSQLInsert = strSQLInsert & VALUE3
dbConnection.Execute strSQLInsert


The problem is that when I test that application and go to a record, the code is not executing because no records are being added to the other table. It has to be in the code because I know the records exist to pull with the parameters I am selecting.
Any help would be really appreciated!
McCree

Sergey Kornilov admin 9/9/2008

Instead of executing he query print it on the page to see if everything looks good. You can also test this query against your database to make sure it works.