Copy cell above in a table

pdvsa

Board Regular
Joined
Apr 22, 2010
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need to update a table: tblImportToAccess.[TradeNo] and tblImportToAccess.[CoName]
with the value that is in the row above it.

example:
TradeNo
CoName
123XYZ
123XYZ
nullnull
333ABC
nullnull


I need the nulls on [TradeNo] and [CoName] to populate with 123 and XYZ respectively for the first null but the second null I would need it to populate with 333 and ABC respectively.
My dataset is much larger and there are different TradeNo and CoName (much like dragging down the cell above in excel).
I am not sure if this would best be done by way of an update query but if so then I have a part of it below and looking for the remainder.
I am a novice user of Access. I can easily do this in excel with a macro but I want to to perform this in access after I import the excel data.

UPDATE tblImportToAccess SET
WHERE (((tblImportToAccess.[TradeNo]) Is Null) AND ((tblImportToAccess.[CoName]) Is Null));

Thank you.
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you do not have a field that imposes some sort of ascending or descending order, then AFAIK you cannot do this. There is nothing in your sample data that governs which record is to be considered as preceding or following any other record. Think of a spreadsheet - while the row numbers may not be part of the sheet data, they are organizing the data. You don't seem to have that. If you try to sort by TradeNo, all of your records with null in this field will be grouped together.
If this is a one time thing and you know how to do it in Excel, I'd suggest you take care of it there. Otherwise, you will have to add a sorting field, such as an autonumber.
EDIT - forgot to say that once you have the sort order field, you will need to use a subquery or write code to do this. For subquery approach see


 
Last edited:
Upvote 0
I am not sure why the mass update with the update statement does not work. You can always loop through the table as a record set and update the the missing values with update edits.


VBA Code:
Set db = CurrentDb 
strSQL = "SELECT * FROM tblName WHERE TadeNo IS NULL"
Set rs = db .OpenRecordset(strSQL, dbOpenDynaset)

If rs.recordcount=0 Then Exit Sub

rs.Movefirst

i= 1 

Do

rs.Edit
rs![TadeNo] = 123
rs.Update 

rs.MoveNext   
i= i+ 1       
Loop until rs.eof

rs.Close   
db.Close    

Set rs = Nothing
Set db = Nothing
 
Upvote 0
Load the data into Power Query and use the Fill Down command.
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,769
Members
448,991
Latest member
Hanakoro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top