bind recordset to subform (1 Viewer)

eword

New member
Local time
Today, 11:36
Joined
Jul 16, 2011
Messages
8
Hi,

I am learning microsoft access and i was trying to work out how i can display the results of a query in a subform. my code is as follows:

Dim con As ADODB.Connection
Dim recSet As Recordset
Dim strFrmNm As String
Dim sqlQuery As String

Set recSet = New ADODB.Recordset
recSet.CursorType = adOpenKeyset
recSet.LockType = adLockOptimistic

Set con = CurrentProject.Connection
sqlQuery = "SELECT * FROM Video WHERE Video.Title='" & Me.vTitle.Value & "';"

recSet.Open sqlQuery, con
strFrmNm = "videoDetails"

DoCmd.OpenForm strFrmNm

' none of these commands seem to work
'Set Application.Forms(strFrmNm).Recordset = recSet
'Set Forms(strFrmNm).Recordset = recSet
'Set Forms!videoDetails.Recordset = recSet
'Set Me!Video.Form.Recordset = recSet
'Set Application.Forms("test")!Video.Form.Recordset = recSet

recSet.Close
con.Close
Set recSet = Nothing
Set con = Nothing


The issue i have is that when i press the button to execute my code data is displayed in a new form rather than the on the current forms subform. The primary form's name is test and the subform's name is videoDetails. The object name that contains the subform is Video.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:36
Joined
Aug 30, 2003
Messages
36,125
I usually only use recordsets to work with data in the background. How about

Forms!Test.Video.Form.RecordSource = sqlQuery
 

eword

New member
Local time
Today, 11:36
Joined
Jul 16, 2011
Messages
8
still the same issue. it opens a form in a seperate window. it does not display the details on the subform. im working in access 2007. i built the subform using the auto tool.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:36
Joined
Aug 30, 2003
Messages
36,125
If the form is already open, why are you opening it again? Try without that line.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:36
Joined
Aug 30, 2003
Messages
36,125
No problem, and welcome to the site by the way.
 

Users who are viewing this thread

Top Bottom