473,395 Members | 1,675 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,395 software developers and data experts.

How do I overwrite table data with a CSV file data?

Here's the overview:

Im building an eCommerce web site using ASP. It has an Access DB at
the back end. Im receiving the Product info from a series of CSV
files. Ive created a Table in Access called 'Products' and the two
fields which concern me are called 'ProductID' and 'Price'. The
product prices change regularly, sometimes quaterly. The updated
prices will be received in the CSV file.

Here's the problem:

I want to somehow get the 'Prices' field in the datbase to be updated
automatically whenver a new CSV file comes in, I dont want to manually
type all the updated prices.

How would I get this done? Can it be done in Access or would I have to
get some sort of ASP program code to do it? Im not a programmer so
would appreciate an 'idiots guide' if poss!

Cheers....John

Jul 21 '06 #1
2 5717
John,

Idiot's guide version? Maybe I'm the wrong guy for that. one way
would be to read the entire file into an empty table, and then run your
update from there via a canned update query. if you wanted the
database to be updated automatically, you could create a form that is
always open and in the OnTimer event, execute the import code.

Here's everything but the timer events:

Option Compare Database
Option Explicit

Public Function GetNewPrices()
On Error GoTo HandleError

'---shut off warnings so the code will run without prompts
DoCmd.SetWarnings False

'---delete any records in holder table because I don't want
leftovers
DoCmd.RunSQL "DELETE * FROM tblNewPriceList;"

'---import the new text file to holder table
DoCmd.TransferText acImportDelim, "NEWPrices Import Specification",
tblNewPriceList, "C:\Documents and
Settings\Piet\Desktop\NEWPrices.txt", False

'---update the current products table with values from the text
file
DoCmd.RunSQL "UPDATE Products INNER JOIN tblNewPriceList ON
Products.ProductID = tblNewPriceList.ProductID SET Products.UnitPrice =
[NewPrice];"

'---delete the text file? or move it?
'---use rename to move the file, Kill to delete it...

'---turn warnings back on.
DoCmd.SetWarnings True

Exit Function

HandleError:
DoCmd.SetWarnings True
MsgBox "Error: " & Err.Number & vbCrLf & "Description: " &
Err.Description, vbOKOnly + vbInformation
Err.Clear
End Function

Okay, before you run off and test this on real data, STOP. This could
potentially munge your work, so test on a BACKUP. (make that mistake
once, and you'll probably never make it again.)

Then you need a _form_ that runs this event on a timer...

Private Sub Form_Timer()
'Show user message...(Getting Prices)
Me.lblFeedback.Visible = True '<---just a label for feedback...
Me.Repaint

'Import all the new data...
GetNewPrices '(calling the function above)

'turn off the label/message, b/c we're done.
Me.Label0.Visible = False
Me.Repaint

End Sub

the form would open when your application opens, but remains hidden.
then just close it when the DB closes. Then your code will run every n
Milliseconds. (So it'll basically watch the folder you specify, so you
should use Rename to move the files that have been un/successfully
imported. The unsuccessful ones you need to check out and retry.

Jul 22 '06 #2
Hi,

Many thanks for the reply - just a couple of questions related to your
answer, to help my understanding of this, sorry if they are a bit basic
as Im not really a programmer, more of a web designer.

When you say read the entire file into an empty table, how would one do
that? Is there a function in Action to do this?

What exactly is a canned update query and where would this run from?

When talking about the import the code, do you mean the CSV file? And
when talking about 'a form that is always open', do you mean a form on
a web page or in Access?

Of all the code youve sent me, where does that go exactly, in an ASP
page?

Thanks in advance....John

you could create a form that is
always open and in the OnTimer event

pi********@hotmail.com wrote:
John,

Idiot's guide version? Maybe I'm the wrong guy for that. one way
would be to read the entire file into an empty table, and then run your
update from there via a canned update query. if you wanted the
database to be updated automatically, you could create a form that is
always open and in the OnTimer event, execute the import code.

Here's everything but the timer events:

Option Compare Database
Option Explicit

Public Function GetNewPrices()
On Error GoTo HandleError

'---shut off warnings so the code will run without prompts
DoCmd.SetWarnings False

'---delete any records in holder table because I don't want
leftovers
DoCmd.RunSQL "DELETE * FROM tblNewPriceList;"

'---import the new text file to holder table
DoCmd.TransferText acImportDelim, "NEWPrices Import Specification",
tblNewPriceList, "C:\Documents and
Settings\Piet\Desktop\NEWPrices.txt", False

'---update the current products table with values from the text
file
DoCmd.RunSQL "UPDATE Products INNER JOIN tblNewPriceList ON
Products.ProductID = tblNewPriceList.ProductID SET Products.UnitPrice =
[NewPrice];"

'---delete the text file? or move it?
'---use rename to move the file, Kill to delete it...

'---turn warnings back on.
DoCmd.SetWarnings True

Exit Function

HandleError:
DoCmd.SetWarnings True
MsgBox "Error: " & Err.Number & vbCrLf & "Description: " &
Err.Description, vbOKOnly + vbInformation
Err.Clear
End Function

Okay, before you run off and test this on real data, STOP. This could
potentially munge your work, so test on a BACKUP. (make that mistake
once, and you'll probably never make it again.)

Then you need a _form_ that runs this event on a timer...

Private Sub Form_Timer()
'Show user message...(Getting Prices)
Me.lblFeedback.Visible = True '<---just a label for feedback...
Me.Repaint

'Import all the new data...
GetNewPrices '(calling the function above)

'turn off the label/message, b/c we're done.
Me.Label0.Visible = False
Me.Repaint

End Sub

the form would open when your application opens, but remains hidden.
then just close it when the DB closes. Then your code will run every n
Milliseconds. (So it'll basically watch the folder you specify, so you
should use Rename to move the files that have been un/successfully
imported. The unsuccessful ones you need to check out and retry.
Jul 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
5
by: Christine Nguyen | last post by:
I've written a program in VB.net. I need to open a file in binary mode and edit it. I cannot find a way to partially overwrite existing data. There are certain hex values I need to replace in the...
3
by: Ritujoy | last post by:
I wasn't able to figure out the vocab to search for this on usenet. I'm sure it's an easy solution, but I have no experience with SQL Server: Situation: tbl_CompanyData is a 1735 x 20 table...
3
by: David Baumgarten | last post by:
I am trying to download a file from a ftp server and if the file already exists to overwrite it. Here is my code: FtpGetFile(hConnection, "1.pdf", FLocation & "\Temp\" & "1.pdf", False, 1, 0,...
1
by: Bernhard Hidding | last post by:
Hello, my program writes an array into a file using the following code: ofstream arrayfile; arrayfile.open("array_file.dat"); .... arraydatei.close(); This works as long as the file does...
6
by: deko | last post by:
Is there a way to set a custom property on Access tables and/or queries to prevent them from being overwritten by import wizards? Any Access database can be easily destroyed if a user mistakenly...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
7
madhoriya22
by: madhoriya22 | last post by:
Hi, I am getting the data from the CSV file and inserting it to the database. Now while inserting I have to check that some of the data(to be inserted) is already existing in the table or not. If...
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.