473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating separate tables from a list in a table

1 New Member
I have 7 tables that need to be updated based on a update query that I have. The field names are all the same and the parameter portion works fine but I can't get the query to access the tables. I was trying to use the table names as a parameter in the query and these parameters are in a table. I have used this query to update one table with multiple parameters and it worked fine but I can't seem to write the code correctly for the tables to be a parameter in the query and update the tables accordingly. Here is my code and the list of tables. Any help would be appreciated.





Expand|Select|Wrap|Line Numbers
  1. Private Sub Command31_Click()
  2.  
  3. Dim R As DAO.Recordset, Rsql As String
  4. Dim SqlCmd As String, Tbl As TableDef, GlobalOpt As String
  5.  
  6. Rsql = "SELECT GlobalOptType,GlobalOptions FROM tblGlobalTables_OPP"
  7.  
  8.  
  9.  Set R = CurrentDb.OpenRecordset(Rsql, dbReadOnly)
  10.  
  11.  Do Until R.EOF
  12.  Tbl = R!GlobalOptType
  13.  GlobalOpt = R!GlobalOptions
  14.  
  15. SqlCmd = "UPDATE tblGlobalSelections_Local_SSP LEFT JOIN "" & Tbl & "" ON (tblGlobalSelections_Local_SSP.SSOPTC = ""  Tbl  "".[SSOPTC])" & _
  16.  " AND (tblGlobalSelections_Local_SSP.SSOPTP = "" & Tbl & "".SSOPTP) SET "" & Tbl & "".SSOPTC = [tblGlobalSelections_Local_SSP].[SSOPTC]," & _
  17.  " " & Tbl & ".SSOPTP = [tblGlobalSelections_Local_SSP].[SSOPTP], "" & Tbl & "".PRICEBRAND = [tblGlobalSelections_Local_SSP].[PRICEBRAND]," & _
  18.  """ & Tbl & "".SSSUFX = [tblGlobalSelections_Local_SSP].[SSSUFX], "" & Tbl & "".SSDESC = [tblGlobalSelections_Local_SSP].[SSDESC]" & _
  19. " WHERE ((("" & Tbl & "".SSOPTC) Is Null) AND (("" & Tbl & "".SSOPTP)=""" & GlobalOpt & """)) OR ((("" & Tbl & "".SSOPTP) Is Null" & _
  20.  " And ("" & Tbl & "".SSOPTP)=""" & GlobalOpt & """)) OR ((("" & Tbl & "".SSOPTP)=""" & GlobalOpt & """) AND (("" & Tbl & "".PRICEBRAND) Is Null))" & _
  21.  " OR ((("" & Tbl & "".SSOPTP)=""" & GlobalOpt & """) AND (("" & Tbl & "".SSSUFX) Is Null)) OR ((("" & Tbl & "".SSOPTP)=""" & GlobalOpt & """)" & _
  22.  " AND (("" & Tbl & "".SSDESC) Is Null));"
  23.  
  24.   CurrentDb.Execute SqlCmd
  25.  
  26.  R.MoveNext
  27.  
  28.  Loop
  29.  
  30.  R.Close
  31.  Set R = Nothing
  32.  
  33.  
  34. End Sub
  35.  
  36.  
  37. Here is the table with the table names:
  38.  
  39. GlobalOptID    GlobalOptType        GlobalOptions
  40. 01              tblBrand_OPP         BRAND
  41. 02              tblConstruction_OPP  CONSTRUCTION
  42. 03              tblDoor_OPP         DOOR STYLE
  43. 04              tblHinge_OPP         HINGE TYPE
  44. 05              tblSQUA_OPP         SQUA/ARCH/CATH
  45. 06              tblWood_OPP         WOOD TYPE
  46. 07            tblFinish_OPP         FINISH
Oct 5 '15 #1
1 862
MikeTheBike
639 Recognized Expert Contributor
Hi

Without you telling us what the problem is it is difficult to be sure, but I think you have too many quotation marks.
You only need to double up the Quotes where you need to include the quotation mark as part of the string.

In you case this will only be needed to delimit the GlobalOpt variable (if it is a text field!?).
I think it should be something like this
Expand|Select|Wrap|Line Numbers
  1. Sql = "UPDATE tblGlobalSelections_Local_SSP LEFT JOIN " & Tbl & " ON (tblGlobalSelections_Local_SSP.SSOPTC = " & Tbl & ".[SSOPTC])" & _
  2.  " AND (tblGlobalSelections_Local_SSP.SSOPTP = " & Tbl & ".SSOPTP) SET " & Tbl & ".SSOPTC = [tblGlobalSelections_Local_SSP].[SSOPTC]," & _
  3.  " " & Tbl & ".SSOPTP = [tblGlobalSelections_Local_SSP].[SSOPTP], " & Tbl & ".PRICEBRAND = [tblGlobalSelections_Local_SSP].[PRICEBRAND]," & _
  4.  " " & Tbl & ".SSSUFX = [tblGlobalSelections_Local_SSP].[SSSUFX], " & Tbl & ".SSDESC = [tblGlobalSelections_Local_SSP].[SSDESC]" & _
  5.  " WHERE (((" & Tbl & ".SSOPTC) Is Null) AND ((" & Tbl & ".SSOPTP)=""" & GlobalOpt & """)) OR (((" & Tbl & ".SSOPTP) Is Null" & _
  6.  " And (" & Tbl & ".SSOPTP)=""" & GlobalOpt & """)) OR (((" & Tbl & ".SSOPTP)=""" & GlobalOpt & """) AND ((" & Tbl & ".PRICEBRAND) Is Null))" & _
  7.  " OR (((" & Tbl & ".SSOPTP)=""" & GlobalOpt & """) AND ((" & Tbl & ".SSSUFX) Is Null)) OR (((" & Tbl & ".SSOPTP)=""" & GlobalOpt & """)" & _
  8.  " AND ((" & Tbl & ".SSDESC) Is Null));"
This assumes all Table and Field names passed as variable do not have spaces in them (square bracket are required if they have).

I have not checked to sql syntax (hopefully this may not be necessary).

HTH


MTB
Oct 5 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
0
by: OursVolant | last post by:
Hello all and thanks in advance for any reply :-) My database has 2 tables; First table is PLAYERS fields are : (ID player) and (rate) Second table is GAMES fields are :
1
by: serge | last post by:
I am running SQL Server Best Practices on a SQL 2000 database and it is recommending me to change the temp tables inside SPs to table variables. I had read already in other places to use table...
1
by: Rob Dob | last post by:
Hi, I have both a Customer and a Orders Table, the key field is CustomerID. I also have a DataGridView that uses a BindingSource created using a join between the Customers table and the Orders...
4
by: Markus Ernst | last post by:
Hi Looking for a possibility to get separate tables rendered with common column widths, I was surprised to see that this code validates: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
0
by: Pasquale | last post by:
I have a form with 8 fields, 4 of which are required and 4 are not. Usually if a field isn't required I would create a separate table for it rather than having a blank value in the table where...
1
by: krizzie khonnie | last post by:
Hi, Can anyone help me? What query should I use if my objective is to check if a record exists in either of the two separate tables.They have the same column name. Ex. Column Name -...
6
by: Dave0291 | last post by:
Hey, I have a problem and I'm kind of new to Access. I'm trying to update a field on one table by multiplying two fields from two separate tables. Now the problem is that every time I try an...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.