?
Solved

OpenRecordSet Invalid Argument

Posted on 2012-04-03
12
Medium Priority
?
1,842 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
  • 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
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!

 
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 2000 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 49

Expert Comment

by:Dale Fye
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

809 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