Solved

open query in a recordset

Posted on 2011-09-08
15
357 Views
Last Modified: 2012-05-12
Hello,

I'm trying to open a query in a recordset and I'm getting a 3061 error.  I've tried to do this in several ways and I've had no luck.  I'm using Access 2010 with SQL Server 2005.  

Any idea would be great.  Thanks!

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb
    strSQL = "Select NHID From qryFaxReminder"
    Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

Open in new window

0
Comment
Question by:eshurak
  • 9
  • 6
15 Comments
 
LVL 75
ID: 36506831
What is the SQL for qryFaxReminder ?

mx
0
 
LVL 3

Author Comment

by:eshurak
ID: 36506863
PARAMETERS [Forms]![frmFaxReminder]![WeekFromNow] DateTime;
SELECT tblFacilityInfo.nhid, tblAdministrator.Administrator, tblContacts.ContactName, tblFacilityInfo.Fax, tblFacilityInfo.Phone, tblFacilities.FNAME, tblFacilityInfo.DateSched1, tblFacilityInfo.DateSched2, tblFacilityInfo.DateSched3, tblAdministrator.ContactNotAdmin
FROM ((tblFacilityInfo LEFT JOIN tblContacts ON tblFacilityInfo.nhid = tblContacts.nhid) INNER JOIN tblFacilities ON tblFacilityInfo.nhid = tblFacilities.nhid) LEFT JOIN tblAdministrator ON tblFacilityInfo.nhid = tblAdministrator.nhid
WHERE (((tblFacilityInfo.DateSched1)=[Forms]![frmFaxReminder]![WeekFromNow]));

Open in new window

0
 
LVL 75
ID: 36506874
Try this ... using Eval()

PARAMETERS [Forms]![frmFaxReminder]![WeekFromNow] DateTime;
SELECT tblFacilityInfo.nhid, tblAdministrator.Administrator, tblContacts.ContactName, tblFacilityInfo.Fax, tblFacilityInfo.Phone, tblFacilities.FNAME, tblFacilityInfo.DateSched1, tblFacilityInfo.DateSched2, tblFacilityInfo.DateSched3, tblAdministrator.ContactNotAdmin
FROM ((tblFacilityInfo LEFT JOIN tblContacts ON tblFacilityInfo.nhid = tblContacts.nhid) INNER JOIN tblFacilities ON tblFacilityInfo.nhid = tblFacilities.nhid) LEFT JOIN tblAdministrator ON tblFacilityInfo.nhid = tblAdministrator.nhid
WHERE (((tblFacilityInfo.DateSched1)=EVAL("[Forms]![frmFaxReminder]![WeekFromNow]") ));
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Author Comment

by:eshurak
ID: 36506917
I'm getting the same results using EVAL.
0
 
LVL 3

Author Comment

by:eshurak
ID: 36506930
The code stops at "Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)"
0
 
LVL 75
ID: 36506938
Really ... ok ...

1) Is that Form open when you run the code?

2) Are there *any* misspelled objects (typos) in [frmFaxReminder]![WeekFromNow]  or the query name itself.

Actually ... may need EVAL in the PARAMETERS part also:


PARAMETERS EVAL("[Forms]![frmFaxReminder]![WeekFromNow]") DateTime;
SELECT tblFacilityInfo.nhid, tblAdministrator.Administrator, tblContacts.ContactName, tblFacilityInfo.Fax, tblFacilityInfo.Phone, tblFacilities.FNAME, tblFacilityInfo.DateSched1, tblFacilityInfo.DateSched2, tblFacilityInfo.DateSched3, tblAdministrator.ContactNotAdmin
FROM ((tblFacilityInfo LEFT JOIN tblContacts ON tblFacilityInfo.nhid = tblContacts.nhid) INNER JOIN tblFacilities ON tblFacilityInfo.nhid = tblFacilities.nhid) LEFT JOIN tblAdministrator ON tblFacilityInfo.nhid = tblAdministrator.nhid
WHERE (((tblFacilityInfo.DateSched1)=EVAL("[Forms]![frmFaxReminder]![WeekFromNow]") ));

mx
0
 
LVL 3

Author Comment

by:eshurak
ID: 36507011
1. Yes form is open.
2. No.  
3. EVAL in PARAMETERS does not work.
0
 
LVL 3

Accepted Solution

by:
eshurak earned 0 total points
ID: 36507032
I'm going this route.

    Dim rs As DAO.Recordset
    Dim qry As DAO.QueryDef
    Set qry = CurrentDb.QueryDefs("qryFaxReminder")
    qry.Parameters("[Forms]![frmFaxReminder]![WeekFromNow]") = [Forms]![frmFaxReminder]![WeekFromNow]
    Set rs = qry.OpenRecordset(dbOpenSnapshot, dbPessimistic)

Open in new window

0
 
LVL 3

Author Comment

by:eshurak
ID: 36507041
Thanks for your help.
0
 
LVL 75
ID: 36507045
Well, that's what Eval() in the SQL gets around ... doing the qry.Parameters in code.  

Does that work ?

mx
0
 
LVL 3

Author Comment

by:eshurak
ID: 36507053
No, the EVAL did not work.

PARAMETERS [Forms]![frmFaxReminder]![WeekFromNow] DateTime;
SELECT tblFacilityInfo.nhid, tblAdministrator.Administrator, tblContacts.ContactName, tblFacilityInfo.Fax, tblFacilityInfo.Phone, tblFacilities.FNAME, tblFacilityInfo.DateSched1, tblFacilityInfo.DateSched2, tblFacilityInfo.DateSched3, tblAdministrator.ContactNotAdmin
FROM ((tblFacilityInfo LEFT JOIN tblContacts ON tblFacilityInfo.nhid = tblContacts.nhid) INNER JOIN tblFacilities ON tblFacilityInfo.nhid = tblFacilities.nhid) LEFT JOIN tblAdministrator ON tblFacilityInfo.nhid = tblAdministrator.nhid
WHERE (((tblFacilityInfo.DateSched1)=Eval("[Forms]![frmFaxReminder]![WeekFromNow]")));

Open in new window

0
 
LVL 75
ID: 36507076
No, I meant what you posted ... re "I'm going this route."

?
0
 
LVL 3

Author Comment

by:eshurak
ID: 36507103
Oh, yes.  The qry.Parameters works.
0
 
LVL 75
ID: 36507119
Very strange ... sorry
0
 
LVL 3

Author Closing Comment

by:eshurak
ID: 36527968
I found this solution without expert assistance.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

778 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