Trim a Field once a csv file has been uploaded to a table

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I think (hope) this is a simple query.

I have created a Macro to pull data from a stored ".csv" file into a table already saved in Access, by re writing over the current data.
The issue is the file once its in could do with a column (or the whole) table trimming to make it easier for me to create queries as I currently have to have another column that trims a field.

Is there anyway I can add a line in to trim [Field3] before the "StatusMsg"?

Code:
Sub ImportCSV(TableName, SourceFilepath, ImportMethod As String)

    Dim StatusMsg As Variant
    
    StatusMsg = SysCmd(acSysCmdSetStatus, "Clearing " & TableName)
    DoCmd.RunSQL "DELETE * FROM " & TableName & ";"
    
    StatusMsg = SysCmd(acSysCmdSetStatus, "Updating " & TableName)
    DoCmd.TransferText acImportDelim, ImportMethod, TableName, SourceFilepath, True
        
    StatusMsg = SysCmd(acSysCmdClearStatus)
End Sub

Sorry if this is an easy one, but my brain is going to sleep after reading so much on it.

thanks in advance
Gavin
 
No, follow ranmans code in post 2 and run that query where you have your update line.
However as that update line is sql and not vba, why not run it as you do the delete sql?
sorry @welshgasman,
I havent done a delete sql before do you have an example of this?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,025
Messages
6,128,354
Members
449,443
Latest member
Chrissy_M

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