473,323 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

How to open Access Database from VBA

I am getting an "invalid database format" error trying to open an Access database from Access VBA. Here is the code:

Expand|Select|Wrap|Line Numbers
  1.   Dim MyConn As ADODB.Connection
  2.     Dim MyRecSet As ADODB.Recordset
  3.     Dim strMake As String
  4.  
  5.     Set MyConn = New ADODB.Connection
  6.     MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\Tools\Test_DB.accdb';"
  7.     MyConn.Open
Any ideas? Thx
May 26 '10 #1

✓ answered by QVeen72

Hi,

there is single quote after Data Source... remove that...

MyConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=c:\Tools\Test_DB.accdb;Persist Security Info=False;"

Regards
Veena

9 7544
QVeen72
1,445 Expert 1GB
Hi,

Connectionstring for .accdb is different..

ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& " Data Source='c:\Tools\Test_DB.accdb;Persist Security Info=False;"

Check This

Regards
Veena
May 26 '10 #2
Is this is the proper code then:

Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim strMake As String

Set MyConn = New ADODB.Connection
MyConn.ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& " Data Source='c:\Tools\Test_DB.accdb;Persist Security Info=False;"

MyConn.Open
MsgBox ("DB4")
May 26 '10 #3
This is the code I have now, but I am getting a format error:

Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim strMake As String

Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='c:\Tools\Test_DB.accdb;Persist Security Info=False;"

MyConn.Open
MsgBox ("DB4")

Error is occuring on MyConn.Open - Error: "format of initialization string does not conform to OLE DB specification".

Where am I going wrong? Thx
May 26 '10 #4
QVeen72
1,445 Expert 1GB
Hi,

there is single quote after Data Source... remove that...

MyConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=c:\Tools\Test_DB.accdb;Persist Security Info=False;"

Regards
Veena
May 26 '10 #5
Thank you removing the ' worked. I think. How do I make the new DB visible?
May 26 '10 #6
QVeen72
1,445 Expert 1GB
Hi,

What do you mean by 'How do I make the new DB visible"...?
May 27 '10 #7
I want to spawn another version/copy of Access as If I manually double-clicked on the 2nd copy of Access. Does that make it clear? What other info can I provide? thank you for your help.
May 27 '10 #8
QVeen72
1,445 Expert 1GB
Hi,

Check If This Helps You
May 27 '10 #9
I am concered about this approach as it is for Access 2000. I am running 2007. This appears to be just what I need, but likely too far down-level.
May 27 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bailee220 | last post by:
I have included the following code to open an Access database form from within an exsisting Access database. But when I run the code, it appears that it opens the database because in windows...
10
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network...
0
by: Bill Thom | last post by:
I have a Microsoft Access 2000 (9.0.4402 SR-1) database that I am attempting to launch from a hyperlink using Internet Explorer (Version 6.0.2800.1106). If I attempt to launch the database from...
10
by: vvenk | last post by:
Hello: When I tried to use an Access database, I get the following exception: Server Error in '/WebGrid' Application....
0
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
6
by: xg | last post by:
Hi, I am writing an ASP page which contains the following code: var MM_DBConn=Server.CreateObject("ADODB.Connection"); MM_DBConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
3
by: ConfusedMay | last post by:
Hi, I've created an access 2003 database that has a form with button called "open complaint database." This complaint database is also in access 2003. Here is my code to open the complaint...
0
by: YosiLeib | last post by:
hi everybody don't know if it's the right place to ask this qustion but I'm new with VB 2005 and need to open Access database in my project (the database was created with VB6). how do I do this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.