UtterAccess.com
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    
 
   
Tallboy
post Aug 9 2017, 04:38 AM
Post#1



Posts: 47
Joined: 17-October 11



Hi,

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?

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

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

End Sub


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


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



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

CODE
    If intCallingForm = 1 Then
        Me.RecordSource = "QryNewRoster2"
    Else
        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 ...
Go to the top of the page
 
Tallboy
post Aug 9 2017, 05:40 AM
Post#3



Posts: 47
Joined: 17-October 11



Hi,

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!


Gerry
Go to the top of the page
 
fkegley
post Aug 9 2017, 07:49 AM
Post#4


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:

Eval('[Forms]![NameOfForm]![NameOfControl]')

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
 
LPurvis
post Aug 9 2017, 07:53 AM
Post#5


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


Hi

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. ;-)

Cheers

--------------------
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    12th December 2017 - 06:41 PM