Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update 2 tables at the same time

Posted on 2014-01-03
3
Medium Priority
?
476 Views
Last Modified: 2014-01-26
Hi everyone,

I like to update 2 tables in access at the same time. My script isn't working. I hope someone can help me out. Thank you in advance, Sander

<%
If (CStr(Request("MM_update")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the update
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_conn_leads_STRING
    MM_editCmd.CommandText = "UPDATE tbl_DAavgAmount SET fin_hist_01_totaal2014 = ?, fin_hist_01_2014 = ?, fin_hist_02_2014 = ?, fin_hist_03_2014 = ?, fin_hist_04_2014 = ?, fin_hist_05_2014 = ?, fin_hist_06_2014 = ?, fin_hist_07_2014 = ?, fin_hist_08_2014 = ?, fin_hist_09_2014 = ?, fin_hist_10_2014 = ?, fin_hist_11_2014 = ?, fin_hist_12_2014 = ? WHERE store_nummer = ?
	

    UPDATE tbl_DAavgPerc SET fin_hist_01_index2014perc = ?, fin_hist_01_2014perc = ?, fin_hist_02_2014perc = ?, fin_hist_03_2014perc = ?, fin_hist_04_2014perc = ?, fin_hist_05_2014perc = ?, fin_hist_06_2014perc = ?, fin_hist_07_2014perc = ?, fin_hist_08_2014perc = ?, fin_hist_09_2014perc = ?, fin_hist_10_2014perc = ?, fin_hist_11_2014perc = ?, fin_hist_12_2014perc = ? WHERE store_nummer = ?"  
	
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_totaal2014"), Request.Form("fin_hist_01_totaal2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_2014"), Request.Form("fin_hist_01_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("fin_hist_02_2014"), Request.Form("fin_hist_02_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("fin_hist_03_2014"), Request.Form("fin_hist_03_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 5, 1, -1, MM_IIF(Request.Form("fin_hist_04_2014"), Request.Form("fin_hist_04_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("fin_hist_05_2014"), Request.Form("fin_hist_05_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("fin_hist_06_2014"), Request.Form("fin_hist_06_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 5, 1, -1, MM_IIF(Request.Form("fin_hist_07_2014"), Request.Form("fin_hist_07_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("fin_hist_08_2014"), Request.Form("fin_hist_08_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5, 1, -1, MM_IIF(Request.Form("fin_hist_09_2014"), Request.Form("fin_hist_09_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 5, 1, -1, MM_IIF(Request.Form("fin_hist_10_2014"), Request.Form("fin_hist_10_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 5, 1, -1, MM_IIF(Request.Form("fin_hist_11_2014"), Request.Form("fin_hist_11_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param13", 5, 1, -1, MM_IIF(Request.Form("fin_hist_12_2014"), Request.Form("fin_hist_12_2014"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param14", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_index2014perc"), Request.Form("fin_hist_01_index2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("fin_hist_01_2014perc"), Request.Form("fin_hist_01_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("fin_hist_02_2014perc"), Request.Form("fin_hist_02_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("fin_hist_03_2014perc"), Request.Form("fin_hist_03_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 5, 1, -1, MM_IIF(Request.Form("fin_hist_04_2014perc"), Request.Form("fin_hist_04_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("fin_hist_05_2014perc"), Request.Form("fin_hist_05_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("fin_hist_06_2014perc"), Request.Form("fin_hist_06_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 5, 1, -1, MM_IIF(Request.Form("fin_hist_07_2014perc"), Request.Form("fin_hist_07_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("fin_hist_08_2014perc"), Request.Form("fin_hist_08_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5, 1, -1, MM_IIF(Request.Form("fin_hist_09_2014perc"), Request.Form("fin_hist_09_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 5, 1, -1, MM_IIF(Request.Form("fin_hist_10_2014perc"), Request.Form("fin_hist_10_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 5, 1, -1, MM_IIF(Request.Form("fin_hist_11_2014perc"), Request.Form("fin_hist_11_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param13", 5, 1, -1, MM_IIF(Request.Form("fin_hist_12_2014perc"), Request.Form("fin_hist_12_2014perc"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param14", 5, 1, -1, MM_IIF(Request.Form("MM_recordId"), Request.Form("MM_recordId"), null)) ' adDouble
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If
End If
%>

Open in new window

0
Comment
Question by:hanskoens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 39753575
You cannot do it
same time
even if database supports distributed transactions.
I doubt it is necessary at all. It is enough to use a basic transaction which guarantees data consistency.

Even if you send insert/update command in the very same microsecond it won't guarantee that data will be written in the same moment. Disk transaction are serialized anyway.

When you are in transaction you could check whether any of updates is made correct record(s) and if not to reject transaction.

You could find initial information here

HTH

Ivo Stoykov
0
 
LVL 1

Accepted Solution

by:
Poseidaon earned 2000 total points
ID: 39756570
Hi Sandler,

You can update / delete / insert many tables as u wish.

First of all i recomend you to write your own codes instead of Dreamweavers insert / update codes. ( i used to use them before but they are kinda pain ) let me show u an example ;

1- Redirect your update form to a new page.( to do this simply type the new address in your form action part  like :
     <form id="form1" name="form1" method="post" action="New_Page.asp">

2- Create New_Page.asp

you can either get form values to variable or directlly use in sql, i prefer getting them to a variable , then compare , then use in sql. to do this.

Name = Request.form("Name")
Surname = REquest.form("Surname")
Etc....

once you get the form values you can do other compare logics.


 
Dim SQL_Process
Dim SQL_Process_cmd
Dim SQL_Process_numRows
Set SQL_Process_cmd = Server.CreateObject ("ADODB.Command")
SQL_Process_cmd.ActiveConnection = MM_conn_leads_STRING



                           
SQL =  "Update User set Name = '"&Name&"', Surname = '"&Surname&"' etc.  "
                              
SQL_Process_cmd.CommandText = SQL
SQL_Process_cmd.Prepared = true

Set SQL_Process = SQL_Process_cmd.Execute

                           
SQL =  "Update User2 set Name = '"&Name&"', Surname = '"&Surname&"' etc.  "
                              
SQL_Process_cmd.CommandText = SQL
SQL_Process_cmd.Prepared = true

Set SQL_Process = SQL_Process_cmd.Execute

Response.redirect("Main_Page.asp")

Hope u got the logic

Please feel free to ask anyquestions if you need
0
 
LVL 2

Author Comment

by:hanskoens
ID: 39759235
Hi Poseidaon,

Thank you very much. This week iam gonna try and wil respond as soon as I did.

Greets Sander
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question