Multiple tables being updated by a single INSERT/UPDATE

dogdays

Active Member
Joined
Apr 28, 2008
Messages
434
Office Version
  1. 2007
Win 7 32 bit, Access 2003
I have created a number of temporary tables at run time, they are unique to a user for the current session. The tables are created by a template of the table with the created table name containing the sign on name of the user, this produces unique table names. The problem I am having is that when I do an INSERT or UPDATE to one of the temporary tables that action is replicated in the template and all the created tables. e.g if I have
template table = tblTemplateDisplay
created tables tblTemplateDisplayJack and tblTemplateDisplayMary
then when I INSERT a row in tblTemplateJack it is also inserted into tblTemplateDisplay and tblTemplateDisplayMary.
The code to create the tables is:
Code:
    ' drop and create a new temporary
    ' the drop is to take into account any changes to the master template of the table
    DoCmd.SetWarnings False
    If utfnTableExists(gstrTempActiveSharesTableName) = True Then
         strQuery = "DROP TABLE " & gstrTempActiveSharesTableName
         DoCmd.RunSQL strQuery
    End If

    ' now create temporary tables for this session, this user
    DoCmd.CopyObject , gstrTempActiveSharesTableName, acTable, gcstrTemplateActiveSharesTableName
Any insights will be appreciated.
tia Jack
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The following code empties the table and then insert data for active shares.
Code:
    ' empty temp table
    strQuery = "DELETE * FROM " & gstrTempActiveSharesTableName
    DoCmd.SetWarnings False
    DoCmd.RunSQL strQuery
    DoCmd.SetWarnings True

 
        strQuery = "INSERT INTO " & gstrTempActiveSharesTableName & "("
        strQuery = strQuery & "nHouseholdNumber, nIndividualNumber, nShareNumber, tShareType, nNumberOfShares, tFullName, tReverseFullName, "
        strQuery = strQuery & "tAddressLine1, tAddressLine2, tAddressLine3, tAddressLine4, tCityStatePostcode, tShareOwnerName,"
        strQuery = strQuery & " cLastPayment, tPaymentForYear, tPaymentReceived, tShare, dtApproved, nYearsOwned"
        strQuery = strQuery & ") VALUES ("
        strQuery = strQuery & shareOwnersRecSet.Fields("nHouseholdNumber") & "," & shareOwnersRecSet.Fields("nIndividualNumber") & ","
        strQuery = strQuery & shareOwnersRecSet.Fields("nShareNumber") & ",'" & shareOwnersRecSet.Fields("tShareType") & "',"
        strQuery = strQuery & iNumberOfShares & ",'"
        strQuery = strQuery & Replace(udtNameAddress.strFullName, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strReverseFullName, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strAddressLine1, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strAddressLine2, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strAddressLine3, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strAddressLine4, "'", "''") & "','"
        strQuery = strQuery & Replace(udtNameAddress.strCityStatePostcode, "'", "''") & "','"
        strQuery = strQuery & Replace(Nz(shareOwnersRecSet.Fields("mComments"), ""), "'", "''") & "',"
        strQuery = strQuery & cPaymentAmount & ",'" & strPaymentForYear & "','"
        strQuery = strQuery & strDateReceived & "','" & strShareNumber & "',#" & shareOwnersRecSet.Fields("dtApproved") & "#,"
        strQuery = strQuery & iYearsOwned
        strQuery = strQuery & ")"
        
        DoCmd.SetWarnings False
        DoCmd.RunSQL strQuery
        DoCmd.SetWarnings True
Jack
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top