Solved

OpenRecordSet Invalid Argument

Posted on 2012-04-03
12
1,681 Views
Last Modified: 2012-04-03
Can anyone help me with an Invalid Argument 3001 on the OpenRecordSet.   I have DAO 3.6 selected in references.

This is my code, just stepping through the code at this point.

Dim strsql As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

strsql = "Select * from SupplierContacts WHERE SuppliercntEmalSelected='Y'"
Set db = CurrentDb
Set rs = db.OpenRecordset(strsql, dbSeeChanges, dbFailOnError)
If Not rs.RecordCount = 0 Then
rs.MoveFirst
Do Until rs.EOF

' email code here

rs.MoveNext
Loop
Else
' do nothing
End If
rs.Close
Set rs = Nothing
Set db = Nothing
0
Comment
Question by:CompTech810
[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
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37800747
change this

Set rs = db.OpenRecordset(strsql, dbSeeChanges, dbFailOnError)

with


Set rs = db.OpenRecordset(strsql)
0
 
LVL 58
ID: 37800771
You can leave the dbSeeChanges, but dbFailOnError is not a valid argument.

Jim.
0
 
LVL 2

Author Comment

by:CompTech810
ID: 37800794
I removed dbFailOnError and im still getting the error 3001.

Set rs = db.OpenRecordset(strsql, dbSeeChanges)
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37800804
i just post

Set rs = db.OpenRecordset(strsql)

Note: *You must use the dbSeeChanges option with OpenRecordset when accessing a SQL Server table that has an IDENTITY column.
The server-generated IDENTITY values cannot be reflected at the client side unless you use the DAO property dbSeeChanges.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 37800812
Should be:

Set rs = db.OpenRecordset(strsql,dbOpenDynaset, dbSeeChanges)

and is SuppliercntEmalSelected a yes/no field or text?  If the latter, it's OK as is but if yes/no, your SQL should be:

strsql = "Select * from SupplierContacts WHERE SuppliercntEmalSelected = True"

Jim.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37800831
in your code, looks like you just want to get the email address from the recordset, so you can simply use

Set rs = db.OpenRecordset(strsql)  ' without the optional arguments.
0
 
LVL 2

Author Comment

by:CompTech810
ID: 37800884
JDettman:  That worked!!!!!  Yeah!!

Capricorn1:  I have to use the dbSeeChanges because I am connected to a SQL database through ODBC.

Now I need the strsql to contain a query not just a simple query.  The query that I wrote references alot of fields that change depending on what contact it is referencing.

How do I add a query in the strsql statement, as you can tell I'm new to VBA....
0
 
LVL 58
ID: 37800919
<<How do I add a query in the strsql statement, as you can tell I'm new to VBA....>>

  For the openrecordset, you just name the query.  The argument can be an SQL string, a table, or the name of a query.

Jim.
0
 
LVL 2

Author Comment

by:CompTech810
ID: 37800955
Ok, I added the query  qryContactsToEmail.

Set rs = db.OpenRecordset(qryContactsToEmail, dbOpenDynaset, dbSeeChanges)

Now I'm getting an error that it can not find the query or it is misspelled.  I know it is spelled correctly because I copy and pasted the name from the query.....   Now what am I missing.....   I really need to take a VBA class.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37801077
you have to enclosed the query or table name in ""

Set rs = db.OpenRecordset("qryContactsToEmail", dbOpenDynaset, dbSeeChanges)
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 37801102
Jim,

You said: "You can leave the dbSeeChanges, but dbFailOnError is not a valid argument"

Why is dbFailOnError not a valid argument?  Access help indicates that the Options argument is "A combination of RecordsetOptionEnum constants that specify characteristics of the new Recordset." and dbFailOnError is one of the RecordsetOptionEnum values.

Access help is not very useful in this sense, and does not give an example.  I would think "a combination" would be identified as the sum of those Enum values, not as a parameter array.  Maybe one of you MVPs can send a note to MS regarding this discrepancy
0
 
LVL 58
ID: 37801542
Your looking at the options for the execute method, which in Access circles is an "action query" (a DML query - something other then a SELECT).

  For the openrecordset, the valid options are:

dbAppendOnly, dbSeeChanges, dbDenyWrite, dbDenyRead, dbForwardOnly, dbReadOnly, dbRunAsync, dbExecDirect, dbInconsistent ,and dbConsistent.


<<Access help is not very useful in this sense, and does not give an example.  I would think "a combination" would be identified as the sum of those Enum values, not as a parameter array.  Maybe one of you MVPs can send a note to MS regarding this discrepancy>>

 We've been complaining about the help since A97<g>.

Jim.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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