-1

I have an access 2010 database that has a main form 'MainForm' and a subform 'SubForm'. The SubForm is attached to the MainForm as a Subform/Subreport object. The user will select a unique identifier from a dropdown and the subform should use that identifier to pull up employee information on the subform. I have tried any number of ways to avail...

Private Sub Dropdown_Exit(Cancel As Integer)
  If IsNull(Me!Dropdown) Or Me!Dropdown= "" Then
    ' nothing to do due to no one selected
  Else
    Forms!MainForm!SubForm.Requery
    ' Forms!SubForm.Requery
    ' DoCmd.OpenForm "SubForm",,,"[ID]=" & me!SubForm!ID,,acDialog
  End If 
End Sub 

The commented out statements are only some of the things I have tried.

Thanks in advance

designspeaks
  • 203
  • 2
  • 11
  • 22

1 Answers1

0

You should be able to do this without any code by specifying the LinkMasterField and LinkChildField properties of the subform control on your main form.

It is clear that LinkChildField should be set to ID in the form design mode. It looks like you'll want to set LinkMasterField to Dropdown. You can set the FilterOnEmptyMaster property to Yes to hide all records before the Dropdown is filled, or No to show all records before Dropdown is specified.

EDIT: If LinkMaster/LinkChild are not appropriate, then code for Dropdown's AfterUpdate event. This fires after a choice is completed via keyboard or mouse. It should look like :

Private Sub Dropdown_AfterUpdate()
    If Len(Me!Dropdown & "") = 0 Then
        '' handle cleared Dropdown
    Else
        Subform.Form.Filter = "[ID] = " & Me!Dropdown
        Subform.Form.FilterOn = True
    End If
End Sub

Changing the filter should update the subform.

pteranodon
  • 2,037
  • 1
  • 13
  • 20
  • The Forms are unbound so it will not allow me to use the LinkMaster and LinkChild. The information is pulled from a behind the scenes SQL query – designspeaks Sep 30 '14 at 20:30