Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Automation error
Richard Stein 
      
2 years ago
I am trying to open an Access database from Excel in order to update a table.  I have tried different ways to pass the string but come up with an automation error

'sets the connection sting to wizard
    DBConStr = "Microsoft.ACE.OLEDB.12.0;Data Source=" & DBLocation.value & ";Persist Security Info=False"

    Dim Cnn As New ADODB.Connection
    'Dim cmd As ADODB.Command
     Cnn.Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Richard W. Stein\Documents\Financial Planning\FPWizard.accdb;Persist Security Info=False"

    'Cnn.Provider = DBConStr
    Cnn.Open
Richard Stein OP  @Reply  
      
2 years ago

Richard Stein OP  @Reply  
      
2 years ago

Richard Rost  @Reply  
          
2 years ago
Nothing jumped out at me, so I asked GPT...

It looks like you are encountering an automation error while trying to open an Access database from Excel using VBA. This issue might be related to the way you're constructing your connection string and how it's assigned to the Provider property of the ADODB.Connection object.

Here's a corrected version of your script that ensures the connection string is properly formatted and applied:


Dim Cnn As ADODB.Connection
Dim DBConStr As String
Dim DBLocation As String

' Set the database location
DBLocation = "C:\Users\Richard W. Stein\Documents\Financial Planning\FPWizard.accdb"

' Construct the connection string
DBConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBLocation & ";Persist Security Info=False;"

' Create a new connection
Set Cnn = New ADODB.Connection

' Assign the connection string to the Connection object
Cnn.ConnectionString = DBConStr

' Open the connection
Cnn.Open


### Key Changes:
1. **Connection String Construction**: I've corrected how the connection string is constructed and assigned. The Provider should be part of the connection string, not separately assigned.
2. **Proper String Concatenation**: Ensure that the connection string is properly concatenated with the DBLocation.
3. **Instantiation of Cnn**: Using Set Cnn = New ADODB.Connection to properly instantiate the connection object.

Make sure that:
- The path to the database is correct and accessible.
- The version of the ACE OLE DB provider you specified (Microsoft.ACE.OLEDB.12.0) is installed on your machine.
- Excel has the necessary permissions to access the file path specified.

This should resolve the automation error. If the issue persists, it may be worth checking for additional details provided by the error message or ensuring that all references required for ADODB.Connection are correctly added to your VBA project (usually via Tools -> References in the VBA editor).
Richard Stein OP  @Reply  
      
2 years ago
I closed Access and opened it up again and the code worked.

Thanks
Richard Rost  @Reply  
          
2 years ago
Haha of course. Always run down the Troubleshooter first.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 4:19:57 AM. PLT: 0s