Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2008, 07:04 AM
Authorized User
 
Join Date: Feb 2008
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hewstone999
Default Importing into Access

I import data from a Spreadsheet into an Access Table. When I import the data I also want to populate one column with name of the Access Table. i.e. i’ve got a table called: MPI_IDS_IFFs so I want my fields to look like this:

ID --- USERNAME --- FORMANE --- TABLE_NAME
01 Hewston Richard MPI_IDS_IFFs
02 Smith John MPI_IDS_IFFs



So far I have this code which imports the data from the spreadsheet into an Access Table.

How can I edit this so I can also insert the table name Value into the “TABLE_NAME” column?

Dim sBuffer As String
Dim file As stcFileStruct

file.strDialogtitle = "Select file to import"
ShowOpenDialog file
sBuffer = file.strFileName
sBuffer2 = file.strFileTitle
strImport = sBuffer
strImport2 = sBuffer2

temp2 = Left$(strImport2, InStrRev(strImport2, ".") - 1)
temp1 = InputBox("Save Table Name as: (Table Name cannot contain 'Spaces' or 'File Extensions')", "SaveAs", temp2)

coltext = temp1

On Error Resume Next
Exists = IsObject(CurrentDb.TableDefs(coltext))

If Exists Then
    Dim Response As Integer
    Response = MsgBox(prompt:="Table already exsists. Overwrite table?", Buttons:=vbYesNo)

    If Response = vbYes Then
        SQLDEL = "DROP TABLE " & coltext
        DoCmd.RunSQL SQLDEL
        SQL = "Create TABLE " & coltext & " (ID Text)"
        DoCmd.RunSQL SQL

        SQL2 = "ALTER TABLE " & coltext & " ADD COLUMN USERNAME Text"
        SQL3 = "ALTER TABLE " & coltext & " ADD COLUMN FORMANE Text"
        SQL4 = "ALTER TABLE " & coltext & " ADD COLUMN TABLE_NAME Text"

        DoCmd.RunSQL SQL2
        DoCmd.RunSQL SQL3
        DoCmd.RunSQL SQL4
        DoCmd.TransferSpreadsheet acImport, 8, coltext, strImport, True, "01-Fields!A1:I5000"


 
Old March 6th, 2008, 08:40 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Why would you want to store the name of the table the data is in when it is the table name itself? IOW, why would you query a column in a table when you must know the very table name you are looking for in order to query it?

Be that as it may, you could create an update query that fills in this column where column = ""

UPDATE MPI_IDS_IFFs
SET MPI_IDS_IFFs.TABLE_NAME = "MPI_IDS_IFFs"
WHERE (((MPI_IDS_IFFs.TABLE_NAME) Is Null)) OR (((MPI_IDS_IFFs.TABLE_NAME)=""));

I think there are some basic design problems that force this solution. HTH


mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
importing flat file into Access 2007 olgolg VBScript 0 March 29th, 2008 07:53 AM
Importing from Excel to Access table DeborahP Excel VBA 3 April 3rd, 2007 03:21 AM
Importing Excel sheet into Access using ASP prasanta2expert ASP.NET 1.0 and 1.1 Basics 1 October 5th, 2006 02:36 PM
Importing Hyperlinks into Access table Sammy8932 Access VBA 0 May 11th, 2005 09:23 AM
Importing files in Access kathy stratton Access 6 February 2nd, 2005 07:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.