• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 913
  • Last Modified:

use of workspace in access 2007

Hi experts

i'm using this code:

Dim ws As Workspace
Set ws = CreateWorkspace("FK", "", "", dbUseODBC)

and that works with access 2003.

Now in access 2007 it tells me that i can't use that code anymore.

How do  I rewrite the code, so it works?
0
DCRAPACCESS
Asked:
DCRAPACCESS
1 Solution
 
Leigh PurvisDatabase DeveloperCommented:
Well - what exactly are you wanting to do?
The error message you cite is quite correct.  Access 2007 no longer supports ODBC Direct workspaces.
That you used to use one implies you have a server database which you wanted to access directly in code without involving Jet at all.  It that about right?  What functions are you performing on the database you access though?
Ironically, given that MS have moved towards advocating linked tables now with 2007 - the recommendation for direct data access is to use ADO instead of DAO with ODBC Direct.  (I can't disagree with that suggestion :-)
So, as an answer to your question, it's tempting to just say "use ADO" - what you're attempting is relevant.
0
 
DCRAPACCESSAuthor Commented:
Hi

I know i have to use ADO, but i don't know how.

But I have found out that this works:

Dim ws As DAO.Workspace
Dim DB As DAO.Database
Set ws = DBEngine.CreateWorkspace("FK", "Admin", "", dbUseJet)
Workspaces.Append ws
Set DB = ws.OpenDatabase("FK", dbDriverComplete, False, "ODBC;DSN=SCDRAPADM")

Set rst = DB.OpenRecordset("select max(jobnr) as max from ondemand_ondemand")
With rst
JOBNR = !Max + 1
.Close
End With
Job.Value = JOBNR

sqlJobSpec = "insert into OnDemand_OnDemand(jobnr,BNR,txt1,txt2,status,maxrc,DT_0) values (" & JOBNR & ", '" & BNR.Value & _
"', '%inc ODPROG(" & OD_Prog & ");', '" & UCase(PORCALC.Value) & "' , 0, 0, SYSDATE)"
 
DB.Execute sqlJobSpec, dbExecDirect

But now it fails in the line that says "DB.Execute sqlJobSpec, dbExecDirect".

Before i was using "Set DB = ws.OpenConnection" but then i got a error. Now i use "Set DB = ws.OpenDatabase" is that a problem?

And instead of using "dbUseODBC" i use "dbUseJet" is that a problem?

I hope that this information is what you seek to help me?

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Looks like Leigh has gone down for the evening ... here's an ADO equivalent:

Dim con As ADODB.Connection
Dim rst As ADODB.Recordset

Set con = New ADODB.Connection
con.Open "Your Connection STring Here"

Set rst = New ADODB.Recordset
rst.Open "select max(jobnr) as max from ondemand_ondemand", con

If Not (rst.EOF and rst.BOF) Then
  Con.Execute "nsert into OnDemand_OnDemand(jobnr,BNR,txt1,txt2,status,maxrc,DT_0) values (" & rst("Max") + 1 & ", '" & BNR.Value "', '%inc ODPROG(" & OD_Prog & ");', '" & UCase(PORCALC.Value) & "' , 0, 0, SYSDATE)"
End If

"Your Connection String" would be the fully formatted connection string to the Server. Check here for examples: www.connectionstrings.com

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now