Wrox Programmer Forums
|
BOOK: Access 2003 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein; ISBN: 9780764559037
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2003 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2007, 11:24 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default odbc system dsn problem hope you can help

I'm trying to set up a system using the odbc drivers so that the front and back end can work over any network once the odbc has been set.

However at the moment I keep getting an error message about the odbc not having the correct parameters ( amount expected = 2) when I try to open a recordset. The other errors it generates relate to the object being closed which I realised is due to the fact that the connection is opening for some reason.

I'm using the code from chapter 12 of beginning access vba as a base for my system.

gcnconn is a global variable declared as a connection
gstrconnection is a global string variable

I've watched the variables and stepped through the code from when the form opens. Each section other than the processrecordset function seems to works fine and returns the results as expected.

The odbc is set up under system dsn as far as I can tell correctly. I seperated out the lines just to see if it was something i'd done in the writing of a single line.

The connection code is:

Sub opendbconnection()

On Error GoTo Handleerror

gstrconnection = "ODBC;DSN=compcontrol;"

'create a new connection instance and open it using the connection
'string
Set gcnconn = New ADODB.Connection
With gcnconn
    .Provider = "MSDASQL"
    .Properties("Data Source").value = gstrconnection
    .Open
End With

Exit Sub

Handleerror:
generalerrorhandler Err.Number, Err.Description, "modstartup", "opendbconnection"
    Exit Sub
End Sub

Function processrecordset(strsqlstatement As String) As ADODB.Recordset

On Error GoTo Handleerror

'open the connection to the database
Call opendbconnection

'create a new instance of a recordset
Dim rscont As New ADODB.Recordset

'set various properties of the recordset

With rscont
    'specify a cursortype and locktype that will allow updates
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    .ActiveConnection = gcnconn
    .Source = strsqlstatement
    'populate
    .Open
    'disconnect the recordset
    .ActiveConnection = Nothing
    'sort the recordset
End With

rscont.Open
'close the connection to the database
Call closedbconnection

'return the recordset
Set processrecordset = rscont

Exit Function

Handleerror:
    generalerrorhandler Err.Number, Err.Description, "moddblogic", "processrecordset"
    Exit Function

End Function


I've looked all over the web for setting up the connections within vba and within odbc and as far as I can tell its right so please help resolve this issue






Similar Threads
Thread Thread Starter Forum Replies Last Post
odbc system dsn problem hope you can help jeremy1048 Access 5 May 9th, 2007 01:19 PM
ODBC DSN connection atoyot BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 December 14th, 2006 06:40 PM
Hope to have a idea for designing this system nadee VB Databases Basics 3 February 24th, 2006 03:24 AM
odbc user dsn in asp.net problem with code ashu10dec ASP.NET 1.0 and 1.1 Professional 0 February 23rd, 2006 09:49 AM
Help Configuring ODBC (DSN) reyboy SQL Language 1 June 10th, 2005 04:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.