473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Updating separate tables from a list in a table

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 860
MikeTheBike
639 Expert 512MB
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.