On Fri, 1 Aug 2008 10:45:47 -0700 (PDT),
(E-Mail Removed) wrote:
>Hello,
>
>I want to transfer data from Excel sheet 'DATA' to Access table
>'300_APO PRICELIST'.
>
>As you can see in the below script I can only append data to the
>Access table, but I also want Access to update the table in case of
>already existing data.
>
I made a few changes to the field names to fit my testing data, so don't
just copy and paste this code.
Do Until MyRecordset.EOF
'Set the record pointer
MyTable.MoveFirst
'This will move the record pointer if code exists
MyTable.Find "[code] = " & [MyRecordset]![code]
'EOF is true if nothing found, so add a new record
If MyTable.EOF Then
MyTable.AddNew
End If
[MyTable]![code] = [MyRecordset]![code]
[MyTable]![Shipto_Customer] = [MyRecordset]![Shipto_Customer]
[MyTable]![Shipto_Customer_Name] =
[MyRecordset]![Shipto_Customer_Name]
[MyTable]![Material_No] = [MyRecordset]![Material_No]
[MyTable]![Material_Name] = [MyRecordset]![Material_Name]
[MyTable]![cal_month] = [MyRecordset]![cal_month]
[MyTable]![Price] = [MyRecordset]![Price]
MyTable.Update
MyRecordset.MoveNext
Loop
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com