Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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 December 1st, 2003, 10:15 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset Issue

Hi Friends,
               I am using Access 2002 with a SQL backend for a project. I am trying to access a table in the database using Recordset, and I am popped with the error.

Object variable or WIth block variable not set

Following is the code-

    Dim DbTmp As Database
    Dim rsCity As Recordset

    Set DbTmp = CurrentDb()

    Set rsCity = CurrentDb.OpenRecordset("Select * FROM [ZIPS]") ' This is the source of error

    rsCity.Find "CITY = '" & Me.CITY.Value & "'"

             I have included the DAO library in my project. I tried using DAO.Database and DAO.Recordset but no luck! I am just not able to figure this thing out. Any help in this matter would be really great for me!
             Thanks you.

Sincerely,
Sameer
 
Old December 2nd, 2003, 10:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Hmmm... without seeing more, here's my first guess. Brackets usually surround field names, not table or query names in SQL code. Therefore, try this. Remove the brackets [] from the SELECT and put it in the FIND criterion. That is,
Code:
Set rsCity = CurrentDb.OpenRecordset("Select * FROM ZIPS")
rsCity.Find "[CITY] = '" & Me.CITY.Value & "'"

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old December 2nd, 2003, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What you need to do, is set the statement to include a dbOpenDynaSet

Set rsCity = CurrentDb.OpenRecordset("Select * FROM [ZIPS]", dbOpenDynaSet)

John
 
Old December 2nd, 2003, 11:08 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And if it's a sql backend, you might need to add dbseechanges.

Beth M
 
Old December 2nd, 2003, 12:32 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are using SQL Server as a backend, do not use currentproject connection to connect to the data, use SQL Server provider, You are bringing the data to Access to crunch.

Also, use ADO instead.



Sal
 
Old December 3rd, 2003, 09:12 PM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sameer,

If you can migrate to ADO, it would be good; however here's what you need to do if you'd like to keep it in DAO - change:

Set rsCity = CurrentDb.OpenRecordset("Select * FROM [ZIPS]")

to

Set rsCity = DbTmp.OpenRecordset("Select * FROM [ZIPS]")

The recordset object needs to be opened under the declared database object, not the CurrentDb. CurrentDb was used to set your database object named dbTmp. This should work as long as the SQL Server table named ZIPS is attached/linked to your database. If you would like help on setting this same scenario using ADO, please let me know.

Good luck.

Warren





Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
Query from Recordset into another Recordset kamrans74 Pro VB Databases 5 March 5th, 2007 04:17 PM
ADODB.Recordset (0x800A0CB3)Current Recordset does tks_muthu Classic ASP Databases 0 June 16th, 2005 07:22 AM
recordset Rudner VB Databases Basics 1 November 11th, 2004 05:18 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





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