Solved

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

Posted on 2011-09-12
7
174 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add records to a form to a table 11 41
Top 1 of each supplier 55 56
Access Crosstab Query with Multiple Values 4 32
DCount Type Mismatch 2 22
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

777 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