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
> Binding An Ado Recordset To A Form Opened In Acdialog Mode., Access 2016    
 
   
javert
post May 25 2020, 09:41 AM
Post#1



Posts: 89
Joined: 18-January 16



Hi, I've run into a sort of chicken and egg problem: I want the user to do operations with records retrieved from a stored procedure call from a MySQL database. I want to use an ADO recordset and bind it to the form but:

rs.open ...
Docmd.openform "TheForm",,,acdialog
Set Forms("TheForm").Recordset = rs

...since the form is opened in acDialog mode, the code that binds the ado recordset to the form won't execute.

Since this code is located within a class module and ideally used from an object, my issue with not opening the Form in acDialog mode is that I will lose track of the execution of the code and, once the form is opened, I won't be able to make another call to the specific object that opened the form.

Can this be overcome with a specific order of operations?
Go to the top of the page
 
theDBguy
post May 25 2020, 09:47 AM
Post#2


UA Moderator
Posts: 78,487
Joined: 19-June 07
From: SunnySandyEggo


Hi. Just curious... Could you try to bind the form in its Open event?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
javert
post May 25 2020, 10:02 AM
Post#3



Posts: 89
Joined: 18-January 16



Maybe, but how do I pass the ado recordset that I build in the code that opened the form to the form itself for it to do the binding?
Go to the top of the page
 
ADezii
post May 25 2020, 11:33 AM
Post#4



Posts: 3,089
Joined: 4-February 07
From: USA, Florida, Delray Beach


Along the same lines of what theDBguy is stating in Post# 2:
  1. In a Standard Code Module Declare a Public Variable of Type ADODB.Recordset, as in:
    CODE
    Public rsADO As ADODB.Recordset
  2. For purposes of this Demo, I'll simply instantiate, then populate, an ADODB Recordset and Open frmDemoADO as acDialog:
    CODE
    Dim strSQL As String

    strSQL = "SELECT * FROM Employees WHERE [State/Province] = 'PA';"
    Set rsADO = New ADODB.Recordset

    With rsADO
      .Source = strSQL
      .ActiveConnection = CurrentProject.Connection
      .CursorType = adOpenKeyset
      .LockType = adLockOptimistic
        .Open
    End With

    DoCmd.OpenForm "frmDemoADO", acNormal, , , acFormEdit, acDialog
  3. In the Open() Event of the called Form (frmDemoADO) 'Bind' the ADO Recordset to the Form's:
    CODE
    Private Sub Form_Open(Cancel As Integer)
      Set Me.Recordset = rsADO
    End Sub
  4. Hope this helps.

This post has been edited by ADezii: May 25 2020, 11:34 AM
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    13th July 2020 - 06:16 AM