Solved

How do you update a value for a table when no join exist

Posted on 2011-09-12
7
175 Views
Last Modified: 2012-05-12
Step 1 - Via MS Access VBA I am looping thru a file directory grabbing all the file names (all MS Excel files) and file paths found and placing them (file names and file paths) in a table call File-Names

Step 2- Still within the loop I then import the MS Excel file into a table called Excel-Import-Data, based on the File Name and File Path found in Step 1.


My quandry is when I import the Excel file into my table called Excel-Import-Data I want to update a field call File Name.  However, since there is no common field/join between the tables Excel-Import-Data and File-Names I am unable tu update the field called File Name.

However, since I am looping thru my directory one file at a time while subsequently doing the import there must be a way to update the field called File Name within the table Excel-Import-Data ?  

Since in the MS Access VBA I am using the docmd command.... to append and update records that may be my shortcoming..Probably there is a way in using a SQL command where I could achieve my goal, but all the Google searches I did on trying to find out on how to achieve this update required the use of a JOIN statement ?

0
Comment
Question by:upobDaPlaya
  • 4
  • 2
7 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 36526843
Does this help?

Importing Standard spreadsheet template

HTH,

Kent
0
 

Author Comment

by:upobDaPlaya
ID: 36526869
Hi Kent,

After looking at your link I still need to somehow take the variable sOpenFile and within my import table update the field call file name with the value found in the variable called sOpenFile....  Any ideas ?
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36526875
Why not just add a field to the Import-Excel-Data table for the file name?

Then once you've imported each file update that field for all the records imported to the filename they've come from.

That should be straightforward but  I think more information on how you are importing would help.

All you've mentioned is DoCmd but not which command or what/where you are importing to.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:upobDaPlaya
ID: 36526889
imnorie,

Thats exactly what I am trying to do..."Then once you've imported each file update that field for all the records imported to the filename they've come from."

However, once I have imported the file what SQL is required to update the Import-Excel-Data table with the Filename.  Within VBA I have always done my updates via the docmd.  In this case an update query using the docmd command is not possible since any query I attempt would lack a join between the Import-Excel-Data table and the File-Names table.
0
 
LVL 33

Assisted Solution

by:Norie
Norie earned 500 total points
ID: 36526967
If you are using the filename to import the data why do you need a join to get it from the table?

That's why I asked for more information on the import process.

This worked for me with the filenames in a field called XLFileName in a table caled tblImportFiles.
Option Compare Database
Option Explicit

Sub ImportXLData()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strFilename As String
Dim strPath As String
Dim strSQL As String

    Set db = CurrentDb

    Set rst = db.OpenRecordset("SELECT XLFileName FROM tblImportFiles")

    rst.MoveFirst

    strPath = "C:\Test\"

    While Not rst.EOF
    
        strFilename = rst!XLFileName

        DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Excel-Import-Data", strPath & strFilename, True, "Data$"

        strSQL = "UPDATE [Excel-Import-Data] SET [Excel-Import-Data].fldSourceFile = '" & strPath & strFilename & "' WHERE fldSourceFile Is Null"

        db.Execute strSQL
        
        rst.MoveNext
        
    Wend

    rst.Close
    
    Set rst = Nothing
    
    Set db = Nothing

End Sub

Open in new window

You could also add a field (Yes/No) for to the filename table to indicate if a file has been imported or not.
0
 

Author Comment

by:upobDaPlaya
ID: 36526989
Thanks imnorie...you are correct I do not need a join, but since I was unsure on how to proceed with the SQL I needed some quidance on the SQL...

Let me give this try and I will let you know how this works...Thanks for your patience on this one,,,its appreciated
0
 

Author Closing Comment

by:upobDaPlaya
ID: 36945874
Thanks imnorie this is the direction I needed..
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 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