ASMELS
Programmer
- Dec 15, 2008
- 7
This routine works fine in A97, but 2007 doesn't like it.
I have a form (AddressMgr) that has a datasheet subform (AddressSubform) that displays customer address data depending on address element selected in option group (PickGroup) on form. Technique is to build SQL record source and pass it to the subform then requery subform to display the records. Here's the code:
Private Sub PickGroup_AfterUpdate()
Dim MyCriteria As String
Select Case Me!PickGroup
Case Is = 1 'Same address
MyCriteria = "((Customer.Address1=[Forms]![AddressMgr]![Address1]))"
Case Is = 2 'Same city & State
MyCriteria = "((Customer.City=[Forms]![AddressMgr]![City]) AND (Customer.State=[Forms]![AddressMgr]![State]))"
Case Is = 3 'Same State
MyCriteria = "((Customer.State =[Forms]![AddressMgr]![State]))"
Case Is = 4 'Same post code
MyCriteria = "((Customer.Post =[Forms]![AddressMgr]![Post]))"
Case Is = 5 'Same country
MyCriteria = "((Customer.Country = [Forms]![AddressMgr]![Country]))"
End Select
'Set subform RecordSource and requery
Forms!AddressMgr!AddressSubform.Form.RecordSource = "SELECT DISTINCTROW Customer.* FROM Customer WHERE " & MyCriteria & " ORDER BY Customer.Name1;"
Forms!AddressMgr!AddressSubform.SetFocus
‘Try it both ways
Forms!AddressMgr!AddressSubform.Form.Requery
Forms!AddressMgr!AddressSubform.Requery
'Reset group to null
Me!PickGroup = 0
End Sub
SQL record source passes to subform just fine, but the requery doesn't seem to work. Any ideas?
ASMEL
I have a form (AddressMgr) that has a datasheet subform (AddressSubform) that displays customer address data depending on address element selected in option group (PickGroup) on form. Technique is to build SQL record source and pass it to the subform then requery subform to display the records. Here's the code:
Private Sub PickGroup_AfterUpdate()
Dim MyCriteria As String
Select Case Me!PickGroup
Case Is = 1 'Same address
MyCriteria = "((Customer.Address1=[Forms]![AddressMgr]![Address1]))"
Case Is = 2 'Same city & State
MyCriteria = "((Customer.City=[Forms]![AddressMgr]![City]) AND (Customer.State=[Forms]![AddressMgr]![State]))"
Case Is = 3 'Same State
MyCriteria = "((Customer.State =[Forms]![AddressMgr]![State]))"
Case Is = 4 'Same post code
MyCriteria = "((Customer.Post =[Forms]![AddressMgr]![Post]))"
Case Is = 5 'Same country
MyCriteria = "((Customer.Country = [Forms]![AddressMgr]![Country]))"
End Select
'Set subform RecordSource and requery
Forms!AddressMgr!AddressSubform.Form.RecordSource = "SELECT DISTINCTROW Customer.* FROM Customer WHERE " & MyCriteria & " ORDER BY Customer.Name1;"
Forms!AddressMgr!AddressSubform.SetFocus
‘Try it both ways
Forms!AddressMgr!AddressSubform.Form.Requery
Forms!AddressMgr!AddressSubform.Requery
'Reset group to null
Me!PickGroup = 0
End Sub
SQL record source passes to subform just fine, but the requery doesn't seem to work. Any ideas?
ASMEL