Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenRecordset error Invalid Argument 3001

Status
Not open for further replies.

tsm1993

Programmer
Sep 18, 2008
11
0
0
US
When I run the following code I get an error 3001: Invalid Argument

Here is my code:

Dim rsinstr As DAO.Recordset
Dim sql As String

sql = "SELECT qryEMS_TestResults.* FROM qryEMS_TestResults WHERE (((qryEMS_TestResults.CourseID)=[Forms]![frmEntry-Field]![cboLocateRoster]));"

Set rsinstr = DBEngine(0)(0).OpenRecordset(sql, dbSeeChanges)

I run something very similar without any problems. I do reference Microsoft DAO 3.6 Object library. If I take the sql code and run it as a query, I do get records. Any help would be greatly appreciated.
 

Try

sql = "SELECT qryEMS_TestResults.* FROM qryEMS_TestResults WHERE (((qryEMS_TestResults.CourseID)=' " & [Forms]![frmEntry-Field]![cboLocateRoster] & " ' ));"
 
Also, if CourseID is a numeric field, leave out the single quote marks, if it is text, leave them in. You also might have to enclose [Forms]![frmEntry-Field]![cboLocateRoster] with Str$ [Forms]![frmEntry-Field]![cboLocateRoster]) if it throws a type mismatch error.
 
Thank you for the suggestion. I tried both and I even tried just throwing in a value and finally added the condition to the query. I get the error: Run-Time Error 3001: Invalid Argument.

The error comes on the line: Set rsinstr = DBEngine(0)(0).OpenRecordset(sql, dbSeeChanges)

Any other ideas?
 

Did you try:
Code:
sql = "SELECT qryEMS_TestResults.* FROM ... "
[red]    
Debug.Print sql[/red]

Set rsinstr = DBEngine(0)(0).OpenRecordset(sql, dbSeeChanges)
And look at the Immediate Window what you get as the value in your sql variable? And if your sql makes any sense, ie. work in Access?

Have fun.

---- Andy
 
If I copy what is in the Immediate Window in to a query, I get data. I switched to:

Dim rs As New ADODB.Recordset

sql = "SELECT qryEMS_TestResults.* FROM qryEMS_TestResults WHERE (((qryEMS_TestResults.CourseID)= " & [Forms]![frmEntry-Field]![cboLocateRoster] & "));"


rs.Open sql, CurrentProject.Connection

It runs fine with that. I had stitched from this in another part of the DB becuase I was getting and error on users machines that are on Access 2010.
 

If it still does not work - could you share with use "what is in the Immediate Window"???

Have fun.

---- Andy
 
The following comes up in the immediate window:

SELECT qryEMS_TestResults.* FROM qryEMS_TestResults WHERE (((qryEMS_TestResults.CourseID)= 1567));

This is what it needs to be. When I pulled the field name out of quotes, as suggested, it started working if I switched to ADO instead of DAO. DAO still gets the same error.
 

First, I would loose all the [tt]((()))[/tt] and play only with:
Code:
SELECT qryEMS_TestResults.* 
FROM   qryEMS_TestResults 
WHERE  qryEMS_TestResults.CourseID = 1567;
not that it will fix your problem, but you don't need them

Have fun.

---- Andy
 
If you want to use DAO, I'd try something like this:
Set rsinstr = DBEngine(0)(0).OpenRecordset(sql[!], dbOpenDynaset[/!], dbSeeChanges)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top