Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why don't work dao recordsets in access 2010

Posted on 2010-11-28
19
Medium Priority
?
1,740 Views
Last Modified: 2012-05-10
i put this in my recordset :

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset

and when i make compile i get this error that point on the "set db":
Compile error:
Invalid outside procedure

and i attach a frame picture from the references

reference.jpg
0
Comment
Question by:bill201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 2
  • +1
19 Comments
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225109
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("select somefiled from table")
0
 

Author Comment

by:bill201
ID: 34225195
i make like you said but i still get the error message on the "set" word
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225211
can you add "Microsoft DAO 3.6 Object Library" in your refrences?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:bill201
ID: 34225222
i tried it and i get this message:
name conflicts with existing module,project or object library
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225223
do you use access 2010 64 bit or 32 bits?

0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225230
do you have AccDB object library in your reference? if yes, uncheck DAO 3.6 and check accDB object library instead?
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225234
if you add AccDB object libary in your refrence, you can try your original code instead.
0
 

Author Comment

by:bill201
ID: 34225243
i have access 32 bit
and i don't see the accdb in my reference where can i found it?
0
 
LVL 85
ID: 34225276
You don't use DAO 3.6 in Access 2007 or 2010. 2007 and 2010 use the new ACE engine, which requires the references you currently have set.

As pddilan suggests earlier, OpenRecordset require a valid SQL Statement or table/query name:

Set rs = db.OpenReocordset("SELECT * FROM SomeTable")

or

Set rs = db.OpenRecordset("qryGetUserNames")

However, it seems you're having trouble on the "Set db = CurrentDB". Is that correct?

You really don't need to use a variable for this. You can do this:

Set rs = Currentdb.OpenRecordset('Your SQL Statement")

If that doesn't work (and you are 100% certain that your SQL statement is valid) then you may have some issues with the installation of Access, or with one of the supporting libraries/files. You may need to do a repair or reinstall of Access or Office.
0
 

Author Comment

by:bill201
ID: 34225291
i don't think that you right and this is the problem because still yesterday i was make all the time recordsets like this and nothing happen and yesterday  without any specific reason (i don't install or update Microsoft office or any other software at all)  it's start to make problems  
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225298
sorry, typo, I meant "acedao.dll"

C:\Program Files\Common Files\Microsoft Shared\Office14\acedao.dll
0
 

Author Comment

by:bill201
ID: 34225301
any way i try this code Set rs = Currentdb.OpenRecordset ("numberst")
and it's not work so i will reinstall access 2010
0
 
LVL 8

Expert Comment

by:pdd1lan
ID: 34225303
so you said you don't have problem yesterday.  maybe you need to repair and compact your databse. j
0
 

Author Comment

by:bill201
ID: 34225310
it's not just in one database it's in  every database that i open even  new one  (except of vba windows where i put before yesterday a recordset there is working and i  can even add more stuff to the code)
0
 

Author Comment

by:bill201
ID: 34225313
i add this file C:\Program Files\Common Files\Microsoft Shared\Office14\acedao.dll

and it's seems that this file was there before and anyway it's  not working
0
 

Author Comment

by:bill201
ID: 34225608
i uninstall office and reinstall it again but the problem remains
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 34225674
<<Compile error:
Invalid outside procedure
>>

 Your references are fine.  What you've done though is placed the statement outside of a Function or Sub Procedure.

  You cannot simply place it at the top of a module.  It must occur inside a procedure. i.e.

Public Function MyTest()

  Dim db as Database
  Set db = CurrentDB()

End function

or


Public Sub MyTest()

  Dim db as Database
  Set db = CurrentDB()

End Sub

  You've got the statement in the wrong place and it needs to be moved.

JimD.
0
 

Author Comment

by:bill201
ID: 34225689
you are so right it's embarrassing that i don't notice this
0
 
LVL 58
ID: 34225694
<<you are so right it's embarrassing that i don't notice this >>

  I tell you it's amazing sometimes what you filter out when reading an error.  I've been caught like that sooo many times myself over the years it is not even funny.

Have a great day,
JimD.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

660 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