X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Dao Code To Assign A Form A Recordset Not Working, Access 2010    
post Aug 9 2017, 04:38 AM

Posts: 47
Joined: 17-October 11


Im using Access 2010. I am trying to change the recordset of a form on the Load event.

I have 2 queries what when I open in the navigator, both open without errors.

Both queries get a parameter from text boxes on another form and provided the form is open both queries work fine.

See my code below which returns error 3061 parameters expected.

Can anyone explain where i'm going wrong?

Private Sub Form_Load()
    Dim rstRoster12 As DAO.Recordset
    If intCallingForm = 1 Then
        Set rstRoster12 = CurrentDb.OpenRecordset("QryNewRoster2", dbOpenDynaset, dbReadOnly)
        Set rstRoster12 = CurrentDb.OpenRecordset("QryRosterHistory2", dbOpenDynaset, dbReadOnly)
    End If

   If rstRoster12.RecordCount > 0 Then
        Set Me.Recordset = rstRoster12
        MsgBox "NO Results Found!"
    End If
    Set rstRoster = Nothing

End Sub

Thanking you !
Go to the top of the page
post Aug 9 2017, 04:47 AM

UtterAccess VIP
Posts: 5,662
Joined: 30-June 11

Would you not simply change the form's Record Source?

    If intCallingForm = 1 Then
        Me.RecordSource = "QryNewRoster2"
        Me.RecordSource = "QryRosterHistory2"
    End If

Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc

All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
post Aug 9 2017, 05:40 AM

Posts: 47
Joined: 17-October 11


Thanks Daniel, that worked great!

The reason I wanted to use DAO was I really wanted to pass in DAO query paramters, but its seems to be a troublesome setup.

So I will follow your example and pass the parameters form controls on forms.

Thanks again!

Go to the top of the page
post Aug 9 2017, 07:49 AM

UtterAccess VIP
Posts: 23,746
Joined: 13-January 05
From: Mississippi

As an aside, I have found using Eval in my queries eliminates the "Parameter Required" error message.

Like this, for example:


The Eval converts the phrase within the ' marks to its value and then passes the value on to the query processor.

The code window does not understand form controls used as query parameters.

Frank Kegley, Microsoft Access 2010 MVP
Go to the top of the page
post Aug 9 2017, 07:53 AM

UtterAccess Editor
Posts: 16,113
Joined: 27-June 06
From: England (North East / South Yorks)


One advantage with opening the recordset first is you can check for the existence of records, and then assign it if there are matches and not bother otherwise.
(As opposed to, say, first counting and then assigning.)
It can be beneficial if your form view would return entirely blank (if record additions wasn't permitted in the form).

Your problem seemed to be opening the recordset itself, rather than in the assignment. And you likely just needed to evaluate form expression parameters in the queries.
For example using fDAOGenericRst instead.

Also, don't close the recordset - you want to keep using it in the form. ;-)


Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    23rd February 2018 - 01:30 AM