[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

OpenRecordSet Invalid Argument

Posted on 2012-04-03
12
Medium Priority
?
1,785 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
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 48

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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