• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

External table is not in the expected format|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / External table is not in the expected format|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosExternal table is not in the expect…
sp_PrintTopic sp_TopicIcon
External table is not in the expected format
Avatar
Lionel Baijot
Member
Members
Level 0
Forum Posts: 119
Member Since:
September 9, 2020
sp_UserOfflineSmall Offline
1
September 6, 2023 - 10:30 pm
sp_Permalink sp_Print

Hi,

I am using the following code to retrieve data from a closed file (.xlsx format). Everything works fine for data retrieval and viewing.

Public Function PickData(oConn As Object, oRec As Object, sSQL As String) As Integer
    'connect to the DB, apply Query, (paste result in  sheet Search), return #result
    'connection DB----------------------------------------------------------------------------------
    oConn.Open CONNSTR_DB
 
    On Error Resume Next
    If oConn.State <> adStateOpen Then
        MsgBox "Error connecting to Database!"
        Exit Function
    End If
    On Error GoTo 0
 
    oRec.Open sSQL, oConn, adOpenStatic, adLockOptimistic, adCmdText
    PickData = oRec.RecordCount '#result
    'ClearSearch
    If PickData <> 0 Then shRecup.Range("M2").CopyFromRecordset oRec
    oRec.Close
    oConn.Close
    'deconnection-----------------------------------------------------------------------------------
End Function

 

----

 
CONNSTR_DB = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;" & _
                       "DATA SOURCE=" & DataPath & DataFile & ";" & _
                       "Extended Properties=""Excel 12.0;HDR=YES;"";"

 

However, when I insert a new line (when I do an UPDATE, everything works correctly), I get an error message 'External table is not in the expected format' and the code stops at the line 'oConn.Open CONNSTR_DB'.

4VQ2I.pngImage Enlarger

 

I've checked the file and everything seems correct in terms of the data, same format etc.

Additional information:
If I pick up the code where it left off and continue via F8, everything works perfectly again. If I then go back to this function, no problem.

If you have any clues, I'd love to hear from you. Thanks in advance.

sp_PlupAttachments Attachments
  • sp_PlupImage 4VQ2I.png (22 KB)
Avatar
Hans Hallebeek
the Netherlands
Member
Members


Trusted Members
Level 0
Forum Posts: 182
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
2
September 7, 2023 - 4:05 pm
sp_Permalink sp_Print

Without the data to help i would suggest you move the On Error Goto 0 line to after the If PickData ... and see what happens

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 688
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
3
September 7, 2023 - 9:18 pm
sp_Permalink sp_Print

Technically, for an xlsx file your extended properties should have Excel 12.0 Xml rather than just Excel 12.0, but that wouldn't explain this issue. It seems odd that you say it occurs only for an insert given that the error occurs before you actually execute any SQL, so it shouldn't really make any difference what type of SQL command it is.

Avatar
Lionel Baijot
Member
Members
Level 0
Forum Posts: 119
Member Since:
September 9, 2020
sp_UserOfflineSmall Offline
4
September 8, 2023 - 7:43 pm
sp_Permalink sp_Print

Hi,

It seems that the db is falling asleep.

So I created a little 'WAKE_UP' macro and everything seems to be working.

Thanks for your comments.

BR,

Lionel

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Shawn Ward, TEJA P, Shoua Lee
Guest(s) 11
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
David von Kleek
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Ashley Hughes
Herbie Key
Trevor Pindling
Forum Stats:
Groups: 3
Forums: 24
Topics: 6528
Posts: 28594

 

Member Stats:
Guest Posters: 49
Members: 32817
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.