Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004

    Unanswered: Set Subform DataSource using Option Group

    I have a form with a subform and an option group with 3 values

    the subform is named frmRecords

    optShowRecords 1 = All - 2=Current 3=Late

    I have 3 queries 1) qryAll 2) qryCurrent 3)qryLate

    I would like to use an if/then statement to set the datasource of the subform to the desired query.

    I tried the code below in the after update of optRecords and it does not work.

    How do I set the datasource of a subform at runtime?

    Thanks in advance - AB


    If Me.optShowRecords = 1 Then
    Me.frmRecords.DataSource = "qryAll"

    If Me.optShowRecords = 2 Then
    Me.frmRecords.DataSource = "qryCurrent"

    If Me.optShowRecords = 3 Then
    Me.frmRecords.DataSource = "qryLate"

    End If


  2. #2
    Join Date
    Dec 2002
    Préverenges, Switzerland
    try RecordSource (instead of DataSource)

    also, if access is thinking straight, it should die on your if, if, if, endif construct.


    select case Me.optShowRecords
    case =1
    me etc
    case =2
    me etc
    case =3
    me etc
    end select

    currently using SS 2008R2

  3. #3
    Join Date
    Feb 2004
    Chicago, IL
    To set the subforms RecordSource:

    Me.frmRecords.Form.RecordSource = "SELECT * FROM qryAll"

    Me.frmRecords.Form.RecordSource = "SELECT * FROM qryLate"

    Me.frmRecords.Form.RecordSource = "SELECT * FROM qryCurrent"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts