Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > BOOK: Beginning Access VBA
|
BOOK: Beginning Access VBA
This is the forum to discuss the Wrox book Beginning Access 2002 VBA by Robert Smith, Dave Sussman, Ian Blackburn, John Colby, Mark Horner, Martin Reid, Paul Turley, Helmut Watson; ISBN: 9780764544026
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Access VBA 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 February 2nd, 2005, 08:21 PM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Begging Access 2003 VBA Ch 5 - connection problem

I have been following the example in page 140 in CH5 about establishing an unbounded recordset. I am using the sample to build my own application.

When I try to open the recordset (line .Open "Compliments_Log", cnCompliments & yes the name is spelt corectly) I get an SQL error as follows:


Invalid SQL statement: expected 'DELETE' 'INSERT' 'PROCEDURE' 'UPDATE' ETC

I have followed the code and checked it several times and cannot see the error. Any help please. The code I have written is as follows:

Dim rsCompliments As ADODB.Recordset
Dim cnCompliments As ADODB.Connection
Dim strCompliments As String
----------------------------------------------------

Private Sub Form_Load()

strCompliments = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Access DataBases\KPI_DataBase.mdb"


'create a new connection instance and open it using the connection string

Set cnCompliments = New ADODB.Connection
cnCompliments.Open strCompliments

'create a new instance of a recordset
Set rsCompliments = New ADODB.Recordset


'set various properties of the recordset
With rsCompliments
    'specify a cursortype and lock type that will allow updates
    .CursorType = adOpenKeyset
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    'open the recordset based on tblCompliments_Log using the existing connection
    .Open "Compliments_Log", cnCompliments
    'disconnect the recordset
    .ActiveConnection = Nothing
End With


Thank you

 
Old February 2nd, 2005, 08:46 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Modify
.Open "Compliments_Log", cnCompliments
as
.Open "select * from Compliments_Log", cnCompliments


http://docs.sun.com/source/817-2514-10/Ch11_ADO123.html

Om Prakash
 
Old February 3rd, 2005, 06:45 PM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by om_prakash
 Modify
.Open "Compliments_Log", cnCompliments
as
.Open "select * from Compliments_Log", cnCompliments


http://docs.sun.com/source/817-2514-10/Ch11_ADO123.html

Om Prakash
Thank you, that worked, I also found the following worked.

 .Open "Compliments_Log", CurrentProject.Connection

Thanks for the link.

Quixote








Similar Threads
Thread Thread Starter Forum Replies Last Post
beg access 2003 vba Michele_Haywood BOOK: Beginning Access VBA 0 November 9th, 2006 09:03 PM
beg access vba 2003 Michele_Haywood Access VBA 0 November 8th, 2006 10:15 PM
Question on Access 2003 VBA Chapter 5 AlexJChang BOOK: Beginning Access 2003 VBA 1 June 7th, 2005 02:04 PM
Question on Access 2003 VBA - Ch5ExampleCode AlexJChang Access 2 June 3rd, 2005 11:10 AM
Access 2003 connection problem umzi ADO.NET 4 July 23rd, 2004 01:04 AM





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