Solved

OpenRecordSet Invalid Argument

Posted on 2012-04-03
12
1,506 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 119

Expert Comment

by:Rey Obrero
ID: 37800747
change this

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

with


Set rs = db.OpenRecordset(strsql)
0
 
LVL 57
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
 
LVL 119

Expert Comment

by:Rey Obrero
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 57

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 119

Expert Comment

by:Rey Obrero
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 57
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 119

Expert Comment

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

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

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 57
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now