Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2236
  • Last Modified:

Combine Tables Access 2010

I have an Access 2010 database.  There are 15 tables.  Each table is named for the product.  Each table has the following fields:  Product Size and Product Cost.  The issue is that many of the products have the same size (12x48).  I need to create something so that one person can access and update all the prices easily from one area instead of opening up each table.  I tried to do a form, but because the fields in each table are the same, it requires a relationship, but each product is NOT related. I am fine with recreating the database, just not sure what best method there is for this.
0
lancecurwensville
Asked:
lancecurwensville
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
you can create a new table  using union query

select * into NewTable From
(
select [Product Size], [Product Cost], 'tableName' as ProductName from tableName
union all
select [Product Size], [Product Cost], 'tableName' as ProductName from tableName


)


change "tableName" with actual names of tables


0
 
Helen FeddemaCommented:
You could make a form with a combo box in the header for selecting the product table, which would then display that table in a subform for editing.  I use this method for editing lookup tables.  See my Access Archon #198 for an article and sample database.  

Here is a link for downloading it:

http://www.helenfeddema.com/Files/accarch198.zip
Here is a screen shot of the form:
Lookup-Table-Edit-Form.jpg
0
 
Helen FeddemaCommented:
For quickly updating the prices, you might be better off using code.  You can make a union query for viewing the data, but union queries are not updatable.
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
What you are doing with the 15 tables is more like an Excel workbook than a relational database.

All the products really should be in a single table. Currently you are using the table name as part of the data. You should add an additional field to the table to hold this data.

Once you get all the data into a single table things will get a lot easier to do.

0
 
lancecurwensvilleAuthor Commented:
@thehitechcoach:  I agree completely, however, the purpose of the database is to allow for mail-merge quoatations in Word, and I did not see an easy way of separating the products and other items on the merge other than to utilize different tables.
0
 
Rey Obrero (Capricorn1)Commented:
<and I did not see an easy way of separating the products and other items on the merge other than to utilize different tables.
>

with creation of the newTable i suggested at http:#a34872814

you can easily separate products using a query

select * from newTable where ProductName="myProduct"

0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
lancecurwensville,

I agree completely, however, the purpose of the database is to allow for mail-merge quoatations in Word, and I did not see an easy way of separating the products and other items on the merge other than to utilize different tables.

That is simple, use a query to filter out the records you need.  You can even simulate having 15 tables by creating 15 queries to filter the data like it was in the separate tables.

What happens if you add a new product? You will have to add a new table and lots of extra work.

I do lots of mail merging with Word. The best way I have found to do a merging  is to never let Word connect to your Access database. I will export out the data to a word merge document format.and merge with this file.  The issue with Word merging with an Access database is that is opens an additional instance of Access in memory to to open the database. This can cause lots of issues.
0
 
Rey Obrero (Capricorn1)Commented:
<You can even simulate having 15 tables by creating 15 queries to filter the data like it was in the separate tables.>

you can use ONE query, use a combo box in a form to filter the query for the product you want to extract from the NewTable.
0
 
Helen FeddemaCommented:
For a mail merge (done in code), you could create filtered queries to create recordsets, and (if necessary) run make-table queries to create temp table for export.  Here is some sample code:
[sample code fragment using the procedure]

   Dim dbs As DAO.Database
   Dim lngCount As Long
   Dim lngID As Long
   Dim rpt As Access.Report
   Dim rst As DAO.Recordset
   Dim strPrompt As String
   Dim strQuery As String
   Dim strRecordSource As String
   Dim strReport As String
   Dim strSQL As String
   Dim strTitle As String
   
   strRecordSource = "tblInventoryItemsComponents"
   strQuery = "qryTemp"
   Set dbs = CurrentDb

   'Numeric filter
   lngID = Nz(Me![ID])
   If lngID <> 0 Then
      strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
         & "[ID] = " & lngID & ";"
   End If

   'String filter
   strInventoryCode = Nz(Me![InventoryCode])
   If strInventoryCode <> "" Then
      strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
         & "[InventoryCode] = " & Chr$(39) & strInventoryCode & Chr$(39) & ";"
   End If

   'Date range filter from custom database properties
   dteFromDate = CDate(GetProperty("FromDate", ""))
   dteToDate = CDate(GetProperty("ToDate", ""))
   strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
      & "[dteDateReceived] Between " & Chr(35) & dteFromDate _
      & Chr(35) & " And " & Chr(35) & dteToDate & Chr(35) & ";"

   'Date range filter from controls
   If IsDate(Me![txtFromDate].Value) = True Then
      dteFromDate = CDate(Me![txtFromDate].Value)
   End If

   If IsDate(Me![txtToDate].Value) = True Then
      dteToDate = CDate(Me![txtToDate].Value)
   End If

   strSQL = "SELECT * FROM " & strRecordSource & " WHERE " _
      & "[dteDateReceived] Between " & Chr(35) & dteFromDate _
      & Chr(35) & " And " & Chr(35) & dteToDate & Chr(35) & ";"

   Debug.Print "SQL for " & strQuery & ": " & strSQL
   lngCount = CreateAndTestQuery(strQuery, strSQL)
   Debug.Print "No. of items found: " & lngCount
   If lngCount = 0 Then
      strPrompt = "No records found; canceling"
      strTitle = "Canceling"
      MsgBox strPrompt, vbOKOnly + vbCritical, strTitle
      GoTo ErrorHandlerExit
   Else
      'Use this line if you need a recordset
      Set rst = dbs.OpenRecordset(strQuery)
   End If

   'Use SQL string as the record source of a form
   strFormName = "fpriLoadSoldPackingSlip"
   DoCmd.OpenForm FormName:=strFormName, _
      view:=acDesign
   Set frm = Forms(strFormName)
   frm.RecordSource = strSQL
   DoCmd.OpenForm FormName:=strFormName, _
      view:=acNormal
   
   'Use SQL string as the record source of a report
   strReport = "rptLoadSold"
   DoCmd.OpenReport ReportName:=strReport, _
      view:=acViewDesign, _
      windowmode:=acHidden
   Set rpt = Reports(strReport)
   rpt.RecordSource = strSQL
   DoCmd.OpenReport ReportName:=strReport, _
      view:=acViewNormal, _
      windowmode:=acWindowNormal

   'The report has the filtered query as its record source

=========================

Public Function CreateAndTestQuery(strTestQuery As String, _
   strTestSQL As String) As Long
'Created by Helen Feddema 28-Jul-2002
'Last modified 6-Dec-2009

On Error Resume Next
   
   Dim qdf As DAO.QueryDef
   Dim rst As DAO.Recordset
   
   'Delete old query
   Set dbs = CurrentDb
   dbs.QueryDefs.Delete strTestQuery

On Error GoTo ErrorHandler
   
   'Create new query
   Set qdf = dbs.CreateQueryDef(strTestQuery, strTestSQL)
   
   'Test whether there are any records
   Set rst = dbs.OpenRecordset(strTestQuery)
   With rst
      .MoveFirst
      .MoveLast
      CreateAndTestQuery = .RecordCount
   End With
   
ErrorHandlerExit:
   Exit Function

ErrorHandler:
   If Err.Number = 3021 Then
      CreateAndTestQuery = 0
      Resume ErrorHandlerExit
   Else
   MsgBox "Error No: " & Err.Number _
      & " in CreateAndTestQuery procedure; " _
      & "Description: " & Err.Description
   End If
   
End Function

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now