Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2004, 09:37 AM
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing data type when importing Excel worksheet

Hello all! I am importing a worksheet from Excel and one of the fields Imports as a number. Since I do not perform any arithmetic on this field, I want it to be a text field (also in case they begin to add letters to this field). Is there anyway I can change the field type during the import procedure or do I have to do it afterwards? Here is my code for the import.

Public Function ImportFileVersion() As Boolean

Dim strPath As String
Dim strSQl As String

'Set the path
strPath = "S:\MIS\admin\MidAtl_Hierarchy_2004.xls"
strSQl = "DELETE * FROM tblHierarchy"

'If table exist, delete and update with latest version
'If table does not exist, continue
On Error Resume Next
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQl
    DoCmd.SetWarnings True

'Import the data only in this range from Excel
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    "tblHierarchy", strPath, True, "A1:H423"

'Open the table
DoCmd.OpenTable "tblHierarchy", acViewNormal

ImportFileVersion = True


End Function

Also if you see how my code can be more efficient, please feel free to chop it up.

Thanks in advance!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Excel Data into a new Dataset Juan Patrick Visual Basic 2005 Basics 2 July 4th, 2007 09:03 PM
Changing Data type samnachilomo SQL Server 2000 1 November 25th, 2006 03:25 PM
Changing Data Type Behaviour mat41 SQL Server ASP 8 August 28th, 2006 07:17 PM
Changing data type error kuku SQL Server 2000 1 August 18th, 2005 10:20 AM
Changing data type JLN Pro VB 6 1 July 13th, 2004 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.