Changing RecordSource in code problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nambr9
    New Member
    • Apr 2012
    • 1

    Changing RecordSource in code problem

    Hello.

    I am trying to change a RecordSource (query) of a subform based on user selection in another form.

    In the code below I am setting the same query as defined on the subform (Property RecordSource), but it returns no records at all.

    Code:
    Private Sub ID_Click()
        Dim fetchedId As Integer
        Dim sql As String
        With Me.Form.Recordset
            Me.Parent.Form!IdHolder = .Fields("Id")
            fetchedId = .Fields("Id")
        End With
        sql = "SELECT MT_Pravice.ID AS ID, MT_Pravice.ID_Meta AS ID_Meta, MT_Pravice.ID_Avtor AS ID_Avtor, MT_Pravice.ID_VrstaPravice AS ID_VrstaPravice , MT_Pravice.PravicaPredlagana AS PravicaPredlagana , MT_Pravice.Pravica AS Pravica , MT_Pravice.Opomba AS Opomba, MT_Pravice.Datum AS Datum, MT_Pravice.Datum_Ureditve AS Datum_Ureditve FROM MT_Pravice"
        Me.Parent!MT_Pravice_DATAFORM.Form.RecordSource = sql
        Me.Parent!MT_Pravice_DATAFORM.Form.Requery
    End Sub
    My goal would be to add an "WHERE ID_Avtor = fetchedId", but even the original query does not work. When the code hits I get empty form.

    Can anyone help me out?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    You don't share much of the details of your structure, which makes helping you more complicated. What relates to what, and what filtering are you looking for in relation to that?

    Comment

    Working...