PC Review


Reply
Thread Tools Rate Thread

.accdm database not recognized in code

 
 
=?Utf-8?B?SkNhbnlvbmVlcg==?=
Guest
Posts: n/a
 
      3rd Apr 2007
I recently converted my database to .accdb format. I forgot however, that I
had code in an excel file that opened the database and created and entered
info in an existing table under a new record. The code no longer works. I
tried changing the hard coded file name to .accdb and got a new error saying
that the database format was not recognized. Is there an easy way to change
the format back (I think it was 2003) or a simple code fix that I can make? I
have around 10 different excel files that do this same code so I will fix all
of them if reverting to the old format is not an option. Here is the code so
you will know better what I am talking about:

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=S:\Time Clock\NJC.accdb"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Jobs", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("Date") = Now()
Select Case Range("D3").Value
Case 1
.Fields("Company") = "Five Star Ford"
Case 2
.Fields("Company") = "Tom Jones Ford"
Case 3
.Fields("Company") = "Courtesy Chevrolet"
End Select
If Range("D2") > 10000 Then
.Fields("Description") = "Service Body and
Options for APS veh# " & Range("D2").Value & "."
Else
.Fields("Description") = "Service Body and
Options for APS veh# 0" & Range("D2").Value & "."
End If
.Fields("HourlyCost") = 60
.Fields("HourlyPrice") = 80
.Fields("Status") = "C"
.Fields("EstimateTot") = Range("E62").Value
If Range("D2") > 10000 Then
.Fields("Link") = Path & Left(Range("D2").Value,
2) & " Series\" & Range("D2").Value & " Service Body " & Range("B1").Value &
".xls"
Else
.Fields("Link") = Path & "0" &
Left(Range("D2").Value, 1) & " Series\0" & Range("D2").Value & " Service Body
" & Range("B1").Value & ".xls"
End If
' add more fields if necessary...
.Update ' stores the new record
End With
Range("D1").Value = rs.Fields("JobNumber")
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

Thanks for any help you can give me with this.
 
Reply With Quote
 
 
 
 
Norman Yuan
Guest
Posts: n/a
 
      3rd Apr 2007
In order to use ADO to connect to *.accdb file, you cannot use existing MS
OLEDB Jet provider, because Access2007 uses new database engine, instead of
Jet. You need to download MS Office Access database engine, if the Excel app
runs on a computer without Access2007 installed. Not like Jet engine, which
comes with all Windows version so far, the new Access database engine only
installed with Access2007. If you need to access *.accdb without Access2007
installed, you need to download and install the new engine. I could not
remember if you need to change the ConnectionString, and also do not
remember the download location. Search MS site should get you there easily.


"JCanyoneer" <(E-Mail Removed)> wrote in message
news:0AC2B41A-881D-4CC6-8505-(E-Mail Removed)...
>I recently converted my database to .accdb format. I forgot however, that I
> had code in an excel file that opened the database and created and entered
> info in an existing table under a new record. The code no longer works. I
> tried changing the hard coded file name to .accdb and got a new error
> saying
> that the database format was not recognized. Is there an easy way to
> change
> the format back (I think it was 2003) or a simple code fix that I can
> make? I
> have around 10 different excel files that do this same code so I will fix
> all
> of them if reverting to the old format is not an option. Here is the code
> so
> you will know better what I am talking about:
>
> Set cn = New ADODB.Connection
> cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
> Source=S:\Time Clock\NJC.accdb"
> ' open a recordset
> Set rs = New ADODB.Recordset
> rs.Open "Jobs", cn, adOpenKeyset, adLockOptimistic,
> adCmdTable
> ' all records in a table
> With rs
> .AddNew ' create a new record
> ' add values to each field in the record
> .Fields("Date") = Now()
> Select Case Range("D3").Value
> Case 1
> .Fields("Company") = "Five Star Ford"
> Case 2
> .Fields("Company") = "Tom Jones Ford"
> Case 3
> .Fields("Company") = "Courtesy Chevrolet"
> End Select
> If Range("D2") > 10000 Then
> .Fields("Description") = "Service Body and
> Options for APS veh# " & Range("D2").Value & "."
> Else
> .Fields("Description") = "Service Body and
> Options for APS veh# 0" & Range("D2").Value & "."
> End If
> .Fields("HourlyCost") = 60
> .Fields("HourlyPrice") = 80
> .Fields("Status") = "C"
> .Fields("EstimateTot") = Range("E62").Value
> If Range("D2") > 10000 Then
> .Fields("Link") = Path &
> Left(Range("D2").Value,
> 2) & " Series\" & Range("D2").Value & " Service Body " & Range("B1").Value
> &
> ".xls"
> Else
> .Fields("Link") = Path & "0" &
> Left(Range("D2").Value, 1) & " Series\0" & Range("D2").Value & " Service
> Body
> " & Range("B1").Value & ".xls"
> End If
> ' add more fields if necessary...
> .Update ' stores the new record
> End With
> Range("D1").Value = rs.Fields("JobNumber")
> rs.Close
> Set rs = Nothing
> cn.Close
> Set cn = Nothing
>
> Thanks for any help you can give me with this.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CD Rom not recognized - Code 19 Qwest_4_Beer Windows XP Hardware 3 15th Apr 2008 11:24 PM
BCM SQL database file not recognized Jim Murphy Microsoft Outlook BCM 1 25th Sep 2007 09:34 PM
Re: Corrupted database, password not recognized ? Rick B Microsoft Access Security 1 5th May 2004 04:34 AM
access database not recognized peterc Microsoft Access 2 18th Mar 2004 09:44 PM
Database format not recognized peter Microsoft Access 1 17th Mar 2004 08:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:30 PM.