ACCESS VBA - Alter table append query

RCBricker

Well-known Member
Joined
Feb 4, 2003
Messages
1,560
I have a form which is used to import worksheets from a file. Each worksheet gets put into its own temp table and then the data is moved into its appropriate table with an append query. However, I am having an issue with one column in particular. When access brings the worksheet into the temp column, it assigns it a data type of number. This field almost never has data in it, but when it does it is two alpha characters. I need it to be data type 'short text'. I have tried the ALTER TABLE option under the docmd.execute and it is not working.

How do I change the data type of a given field in an ACCESS table?

Code:
514                 DoCmd.TransferSpreadsheet acImport, _
                        acSpreadsheetTypeExcel12, strTBLNAME, strFULLPATH, _
                        True, "IMPORT_NAME"

On Error Resume Next
515                 db.Execute "ALTER TABLE strtblname ALTER COLUMN [SCLIN] text"
On Error GoTo ErrCapture
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
In the source table, Excel can get confused about the datatype so it 'guesses', (and does so wrong)
so to fix, I have code to change EVERY cell in the 'confused' column to text.
This way it imports correctly every time.

Code:
Sub Cvt2Text()
range("B2").select
While ActiveCell.row <= 155
  if activecell.text <>"" then  ActiveCell.text= "'" & ActiveCell.text
   ActiveCell.Offset(1, 0).Select
Wend
End Sub
 
Upvote 0
Try importing to existing tables which have the fields set up with the correct data type(s).
 
Upvote 0

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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