Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2004, 10:17 AM
Registered User
 
Join Date: Nov 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Insert Loop

Hi Guys,

I am looking for a solution to the complicated problem which follows:

I have three database tables Emails, Contacts and Actions

I have made an asp page which takes an email from the Emails table and sends it to the appropriate paople in the Contacts table. This works fine and the loop runs through correctly sending the email to each person.

However, I also require the loop to insert information into the Actions table so all correspondance with each contact person is recorded for administration purposes.

The loop continues to run correctly sending each email but only one is recorded in the Actions table.

Can anyone help me please?

here is the code I am using:

PS. all the code is run on a page automaticaly with no user interaction to submit the form required.

<%@LANGUAGE="VBSCRIPT"%>

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_connS4Gtacts_STRING
  MM_editTable = "Actions"
  MM_editRedirectUrl = "Default.asp"
  MM_fieldsStr = "ContactID|value|CompID|value|EmailID|value|MarkCa mpID|value|Action|value"
  MM_columnsStr = "ContactID|none,none,NULL|CompanyID|none,none,NULL |EmailID|none,none,NULL|MarketingCampID|none,none, NULL|ActionTaken|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")

  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim RS_GetContacts__MMColParam
RS_GetContacts__MMColParam = "101"
If (Request("MM_EmptyValue") <> "") Then
  RS_GetContacts__MMColParam = Request("MM_EmptyValue")
End If
%>
<%
Dim RS_GetContacts
Dim RS_GetContacts_numRows

Set RS_GetContacts = Server.CreateObject("ADODB.Recordset")
RS_GetContacts.ActiveConnection = MM_connS4Gtacts_STRING
RS_GetContacts.Source = "SELECT * FROM Contacts WHERE CompID = " + Replace(RS_GetContacts__MMColParam, "'", "''") + ""
RS_GetContacts.CursorType = 0
RS_GetContacts.CursorLocation = 2
RS_GetContacts.LockType = 1
RS_GetContacts.Open()

RS_GetContacts_numRows = 0
%>
<%
Dim RS_GetEmail__MMColParam
RS_GetEmail__MMColParam = "1"
If (Request.QueryString("EmailID") <> "") Then
  RS_GetEmail__MMColParam = Request.QueryString("EmailID")
End If
%>
<%
Dim RS_GetEmail
Dim RS_GetEmail_numRows

Set RS_GetEmail = Server.CreateObject("ADODB.Recordset")
RS_GetEmail.ActiveConnection = MM_connS4Gtacts_STRING
RS_GetEmail.Source = "SELECT * FROM Emails WHERE EmailID = " + Replace(RS_GetEmail__MMColParam, "'", "''") + ""
RS_GetEmail.CursorType = 0
RS_GetEmail.CursorLocation = 2
RS_GetEmail.LockType = 1
RS_GetEmail.Open()

RS_GetEmail_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
RS_GetContacts_numRows = RS_GetContacts_numRows + Repeat1__numRows
%>
<html>
<head>

</head>
<body>
<%
While ((Repeat1__numRows <> 0) AND (NOT RS_GetContacts.EOF))
%>
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
  <input name="ContactID" type="text" id="ContactID4" value="<%=(RS_GetContacts.Fields.Item("ContactID") .Value)%>">

<input name="CompID" type="text" id="CompID5" value="<%=(RS_GetContacts.Fields.Item("CompID").Va lue)%>">

<input name="EmailID" type="text" id="EmailID5" value="<%=(RS_GetEmail.Fields.Item("EmailID").Valu e)%>">

<input name="MarkCampID" type="text" id="MarkCampID3" value="<%=(RS_GetEmail.Fields.Item("MarketingCamp" ).Value)%>">
  <input name="Action" type="text" id="Action" value="Email">
  <input type="hidden" name="MM_insert" value="form1">

</form>
<script type="text/javascript">

    form1.submit();

</script>


<%

strTEXT=strTEXT&(RS_GetEmail.Fields.Item("EmailMes sage").Value) &"<br>"


'Dimension variables
Dim objCDOSYSCon

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.search4grads.com"

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon

objCDOSYSMail.From = "[email protected]"

objCDOSYSMail.To = (RS_GetContacts.Fields.Item("ContactEmail").Value)

objCDOSYSMail.Subject = (RS_GetEmail.Fields.Item("Subject").Value)

objCDOSYSMail.HTMLBody = strTEXT

objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
<%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RS_GetContacts.MoveNext()
Wend
%>

<%
RS_GetEmail.Close()
Set RS_GetEmail = Nothing
%>
<%
RS_GetContacts.Close()
Set RS_GetContacts = Nothing
%>
 
Old November 7th, 2004, 09:26 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default


Already posted at

  http://p2p.wrox.com/forum.asp?FORUM_ID=54


--------
Rajani






Similar Threads
Thread Thread Starter Forum Replies Last Post
insert value into multiple table AzlanAziz SQL Language 5 January 12th, 2007 06:01 AM
Multiple Insert tsimsha Classic ASP Basics 1 January 19th, 2005 07:48 AM
Multiple Insert Loop HeadMelt Classic ASP Basics 3 November 8th, 2004 08:31 AM
Using loop to change text of multiple textboxes snowy0 VB.NET 6 July 29th, 2004 08:54 AM
Multiple value insert mateenmohd SQL Server 2000 3 October 7th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.