Can you change a form recordsource?

  • Thread starter Thread starter ryan.fitzpatrick3
  • Start date Start date
This is what I have

Private Sub cboxMonth_AfterUpdate()

If Nz(Me!cboxMonth, 0) = 0 Then
' If the combo is Null, use the whole table as the RecordSource.
Me!Forms!frmItemVolumeSpend.RecordSource =
"QryAdageVolumeSpendYear"

Else
' If not Null, it uses a query to bring the only vendors that
match the branch
Me!Forms!frmItemVolumeSpend.RecordSource = "QryAdageVolumeSpend"

End If
End Sub
 
You can change either. But you must have the syntax correct.

If you are wanting to change the recordsource for the current form, use:
Me.RecordSource = "NameOfRecordSource"

You cannot use Me.Forms...., because a form does not contain the Forms
collection. You can use that syntax to change the recordsource of a
different form, but you must omit the Me:
Forms.FormName.RecordSource = "NameOfRecordSource"

If you want to change the recordsource of a subform on the current form use:
Me.NameOfSubformcontrol.Form.RecordSource = "NameOfRecordSource"

HTH,

Rob
 
Why are you doing that rather than just filtering the form?

This is what I have

Private Sub cboxMonth_AfterUpdate()

If Nz(Me!cboxMonth, 0) = 0 Then
' If the combo is Null, use the whole table as the RecordSource.
Me!Forms!frmItemVolumeSpend.RecordSource =
"QryAdageVolumeSpendYear"

Else
' If not Null, it uses a query to bring the only vendors that
match the branch
Me!Forms!frmItemVolumeSpend.RecordSource = "QryAdageVolumeSpend"

End If
End Sub
 
Back
Top