Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:14:23+00:00 2026-05-31T21:14:23+00:00

I’m trying to import an excel file Excel97-2003 (the first sheet only) into an

  • 0

I’m trying to import an excel file Excel97-2003 (the first sheet only) into an Access database. for that I’m using the following code :

Dim cnnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.Recordset
With cnnExcel
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=" & strFileSelected & ";" & "Extended Properties=Excel 8.0"
    .CursorLocation = adUseClient
    .Open
End With

rsExcel.Open "SELECT * FROM [Sheet1]", cnnExcel

All the columns in the excel file are string and have type “General” (no special format) when you open it with Excel2003) and the 3 other columns are dates.
My problem is I get null for value which exist in the cell.For exemple if the first value is string than if there’s an integer in that columns it will be returned as null and vice-versa
Is there any solution for this?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:14:24+00:00Added an answer on May 31, 2026 at 9:14 pm

    Solution 1

    Using your code, I was able to properly load data from an Excel Sheet without problem.
    However, please check your SQL Query, it should be something like:

    rsExcel.Open "SELECT * FROM [Sheet 1$]", cnnExcel
    

    The rules for the FROM part as as follow:

    • Query from for an entire worksheet:
      SELECT * FROM [SheetName$], note the $
    • Query from a range:
      SELECT * FROM [SheetName$A1:C5]
    • Query from a named range:
      SELECT * FROM NameRange
    • Query from a worksheet that has non-alphanumerical characters:
      SELECT * FROM ['This;is.My SheetName$']

    Code working on my machine:

    Dim cnnExcel As Object
    Dim rsExcel As Object
    Set cnnExcel = CreateObject("ADODB.Connection")
    Set rsExcel = CreateObject("ADODB.RecordSet")
    With cnnExcel
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "Data Source=D:\Query1.xls;Extended Properties=Excel 8.0"
        .CursorLocation = 3
        .Open
    End With
    
    rsExcel.Open "SELECT * FROM [Sheet 1$]", cnnExcel
    Debug.Print rsExcel.RecordCount '  Prints the number of rows containing data '
    Do
        Debug.Print "Col1: " & rsExcel.Fields(0) & "  - Col2: " & rsExcel.Fields(1)
        rsExcel.MoveNext
    Loop While Not rsExcel.EOF
    rsExcel.Close
    

    Solution 2

    You may have better luck with manipulating the Excel workbook directly.
    Let’s assume that you have a table MyTable in your Access database where you want to import in the fields myA, myB and myC (that have the proper datatype you expect!) the content of your Excel Sheet 1 that has corresponding columns.

    The simplified VBA code would look like this:

    Sub ImportData(fname As String)
        Dim xlo As Object
        Dim xlWb As Object
        Dim xlWs As Object
        Dim colA, colB, ColC As Variant
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim thereIsData As Boolean
        Dim row As Integer
    
        ' Open Excel sheet, try to re-use Excel if it is open '
        On Error Resume Next
        Set xlo = GetObject("Excel.Application")
        If xlo Is Nothing Then Set xlo = CreateObject("Excel.Application")
        On Error Goto 0
        Set xlWb = xla.Workbooks.Open(fname)
        Set xlWs = xlWb.Worksheets(1)  ' Sheet 1'
    
        ' Open table where the results will be stored '
        Set db = CurrentDb()
        Set rs = db.OpenRecordset("MyTable", dbOpenDynaset)
        Do
           colA = xlWs.Cells(row, 1).Value
           colB = xlWs.Cells(row, 2).Value
           colC = xlWs.Cells(row, 3).Value
           ' We will stop at the first empty row '
           thereIsData = Not (IsBlank(colA) And IsBlank(colB) And IsBlank(colC))
           If thereIsData Then
                ' Add the Excel data to the table '
                rs.AddNew
                    rs!myA = colA
                    rs!myA = colB
                    rs!myA = colC
                rs.Update
           End If
           row = row + 1
        Loop While thereIsData
        rs.Close
        ' Cleanup '
        Set rs = Nothing
        Set db = Nothing
        Set xlWs = Nothing
        Set xlWb = Nothing
        xla.DisplayAlerts = False
        xla.Quit
        Set xls = Nothing
    End Sub
    
    '-----------------------------------------------------------------------------  
    ' True if the argument is Nothing, Null, Empty, Missing or an empty string .  
    '-----------------------------------------------------------------------------  
    Public Function IsBlank(arg As Variant) As Boolean  
        Select Case VarType(arg)  
            Case vbEmpty  
                IsBlank = True  
            Case vbNull  
                IsBlank = True  
            Case vbString  
                IsBlank = (arg = vbNullString)  
            Case vbObject  
                IsBlank = (arg Is Nothing)  
            Case Else  
                IsBlank = IsMissing(arg)  
        End Select  
    End Function  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.