Report - Retreiving the Wrong Records

GMSRE

Registered User.
Local time
Today, 08:27
Joined
Apr 27, 2011
Messages
29
Hello

I am working in Access 2007. I am trying to generate a report "Community_Records" that will only retrieve records that are associated with a specific community. For example when I select community ID “00001” all the records for all the communities are retrieved instead of the records that are only associated community ID “00001”. Listed below is the code I am using. What am I doing wrong? Your help will be greatly appreciated. Thank you. GMSRE

Private Sub cmdComRecords_Click()
Dim strFilter As String
strFilter = ""
strFilter = strFilter & " AND CommunityID = '" & Me.ComList & "'"
DoCmd.OpenReport "Community_Records", acViewPreview
End Sub

Private Sub ComList_AfterUpdate()
Me.ComList = Null
Me.ComList.Requery
Me.ComList = Me.Community.ItemData(0)
Me.FindRECID = Null
Me.FindRECID.Requery
Me.FindRECID = Me.Community.ItemData(0)
End Sub
Private Sub State_AfterUpdate()
Me.County = Null
Me.County.Requery
Me.County = Me.County.ItemData(0)
End Sub
Private Sub County_AfterUpdate()
Me.ComList = Null
Me.ComList.Requery
Me.ComList = Me.Community.ItemData(0)
End Sub
 
You create but don't use the string. Try


DoCmd.OpenReport "Community_Records", acViewPreview, , strFilter
 
Hi Paul,

I tried DoCmd.OpenReport "Community_Records", acViewPreview, , strFilter. I still get all the records instead of the ones the records assoicated with community I selected from the list.
Thank you.

GMSRE
 
Just noticed the AND. Try without it:

strFilter = "CommunityID = '" & Me.ComList & "'"
 

Users who are viewing this thread

Back
Top Bottom