Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default .accdm database not recognized in code

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default .accdm database not recognized in code

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell value not recognized by code. Brady Excel Discussion (Misc queries) 8 December 21st 06 02:56 AM
database to Find customer by zip code fjfino Excel Discussion (Misc queries) 0 August 29th 06 09:00 PM
Building a zip code database Rob Excel Programming 1 November 21st 05 05:36 PM
Code to 'lookup' value in Access database maacmaac Excel Discussion (Misc queries) 0 September 16th 05 02:52 AM
how do you break the link with MS Query - Database via code JulieD Excel Programming 3 June 11th 04 02:56 PM


All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"