Calling a Subform

G

Graham Naylor

Hi,

I've got a form with a subform and a Combo Box, I would like to change the
record source of the subform depending on the value selected in the Combo
box.

I've got as putting some code in the combo box's after update procedure but
I can't work out the correct syntax for changing the subform's record
source.

Any help would be much appreciated.

Thanks

Graham
 
B

Bob Barnes

Here's some code from a Frame. You should be able to
adapt it to the ComboBox result you get.

Private Sub Frame527_AfterUpdate()
Dim M$
bNeedDrug = False: bNeedInvDate = False
Select Case Frame527
Case 0
Exit Sub
Case 1
If Not IsNull(cboTheDrug) Then
M = "BrandName = """ & cboTheDrug & """"
Me.SubMeds.Form.RecordSource = "ForMeds"
Me.SubMeds.Form.Filter = M
Me.SubMeds.Form.FilterOn = True
Else
bNeedDrug = True
MsgBox "Please Select A Drug.", , "MAP"
cboTheDrug.SetFocus: cboTheDrug.Dropdown
End If
Case 2
Me.SubMeds.Form.RecordSource = "InvoiceMeds"
Case 3
Me.SubMeds.Form.RecordSource = "ForMeds"
Me.SubMeds.Form.OrderBy = "BrandName, InvDate DESC"
Me.SubMeds.Form.OrderByOn = True
Me.SubMeds.Form.FilterOn = False
Case 4
Me.SubMeds.Form.RecordSource = "MostRecentMeds"
'Me.SubMeds.Form.Requery
Case 5
If Not IsNull(cboInvDate) Then
M = "InvDate = #" & cboInvDate & "#"
Me.SubMeds.Form.RecordSource = "ForMeds"
Me.SubMeds.Form.Filter = M
Me.SubMeds.Form.FilterOn = True
Else
bNeedInvDate = True
MsgBox "Please Select An InvDate.", , "MAP"
cboInvDate.SetFocus: cboInvDate.Dropdown
End If
End Select
End Sub

HTH - Bob
 
G

Graham Naylor

Thanks Bob, all up and running, yet another case of so near but so far!

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top