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?
DCRAPACCESSAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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?

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.