Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

currentproject.connection vs connection string ms access / sql server

Posted on 2014-10-29
6
Medium Priority
?
249 Views
Last Modified: 2015-01-14
I have a function that was written in DAO against ms access mdb backend that i have converted to sql server backend with linked tables.

I have linked tables.  The function uses transactions which i have already determined to not work with DAO and SQL Server based on experience and research.  So i went about converting to ado.

the transactjon setup was
  Dim NewCheck As New adodb.Recordset
 Set TransTemp = DBEngine.Workspaces(0)
    Set CurDb = TransTemp.Databases(0)
   TransTemp.BeginTrans

i am opening the recordset like this:

      NewCheck.Open sqlstmt, CurrentProject.Connection, adUseClient, adLockBatchOptimistic

 NewCheck.AddNew
       NewCheck![Trans Type] = "Check"
       NewCheck![Account Number] = Account
       NewCheck![Check Number] = NextCheckNum
       NewCheck![Check Date] = Me.Check_Date
       NewCheck![Payee] = ChecksToPay![Supplier Name]
       NewCheck![Supplier Number] = ChecksToPay![Supplier Number]
       NewCheck![Payment Amount] = PmtAmt
       NewCheck![Deposit Amount] = 0
       NewCheck![CurrencyCode] = CurCode
       NewCheck![ExchangeRate] = ExChgRate
       NewCheck![Bill Payment] = True
       NewCheck![Posted] = True
       NewCheck![Memo] = "some memo" ' for SQL Contraint
       NewCheck![Posting GL ID] = "0" ' for SQL Contraint
       NewCheck![Voucher] = "some voucher" ' for SQL Contraint.  this is written later in function


...

 NewCheck.Update
       NewCheck.MoveLast ', NewCheck.LastModified


  TransTemp.CommitTrans


It runs without any error, but does not actually write a new record at all.

Do i need a connection string or will currentproject.connection suffice?  Is the DBEngine.Workspaces(0) workspace even the same workspace as my ado connection??

Press
0
Comment
Question by:pressMac
  • 5
6 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40412479
I start with
Dim cnn As ADODB.Connection

Then
Set cnn = CurrentProject.Connection

and finally

NewCheck.Open sqlstmt, CurrentProject.Connection, adUseClient, adLockBatchOptimistic

Have you explicitly Dim'd the connection as ado as you have done with the Recordset?


Kelvin
0
 

Author Comment

by:pressMac
ID: 40413095
This looks like you create the cnn object, but then don't use it when opening the recordset.  

NewCheck.Open sqlstmt, cnn, adUseClient, adLockBatchOptimistic.

So i tried it anyway, and then that make another statement break earlier in the code like so:

   ChecksToPay.Open sqlstmt, CurrentProject.Connection

"Run-TIme error '3251', current provider does not support the necessary interface for Index functionality."
0
 

Author Comment

by:pressMac
ID: 40413098
PS:  the ChecksToPay is dim'd this way:
  Dim ChecksToPay As New ADODB.Recordset
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:pressMac
ID: 40416794
in this function some of the recordsets opened are in SQL Server, and others are in a local tmp .mdb file.  So the currentproject.connection points to the frontend file that is open.  So how to i open directly without odbc, the sql table and the tmp table?
0
 

Accepted Solution

by:
pressMac earned 0 total points
ID: 40541632
There were still some DAO recordsets nested in the transaction.  I removed those and then it worked.
0
 

Author Closing Comment

by:pressMac
ID: 40548528
Other answers to not fix problem.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question