PC Review


Reply
Thread Tools Rate Thread

Display a message box with a count of filtered records.

 
 
stockton12
Guest
Posts: n/a
 
      6th Nov 2008
I have a search form that searches criteria based on a user's response. I
would like to display a count of all the filtered records that this code
produces. Can someone assist me with this?



Private Sub cmdSearch_Click()


If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."

Else


'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"

'Filter frmQA based on search criteria
Form_frmQA.RecordSource = "select * from tblQA where " & GCriteria
Form_frmQA.Caption = "Q&A (" & cboSearchField.Value & " contains '*"
& txtSearchString & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmSearch"

MsgBox "Results have been filtered."


End If

End Sub




 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      6th Nov 2008
Use DCount, and use your GCriteria as the Where clause, something like this:

Dim RecCount as Integer
RecCount = DCount("*","[tblQA]",GCriteria)
MsgBox "Record count " & RecCount

"stockton12" wrote:

> I have a search form that searches criteria based on a user's response. I
> would like to display a count of all the filtered records that this code
> produces. Can someone assist me with this?
>
>
>
> Private Sub cmdSearch_Click()
>
>
> If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
> MsgBox "You must select a field to search."
>
> ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
> MsgBox "You must enter a search string."
>
> Else
>
>
> 'Generate search criteria
> GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
>
> 'Filter frmQA based on search criteria
> Form_frmQA.RecordSource = "select * from tblQA where " & GCriteria
> Form_frmQA.Caption = "Q&A (" & cboSearchField.Value & " contains '*"
> & txtSearchString & "*')"
>
> 'Close frmSearch
> DoCmd.Close acForm, "frmSearch"
>
> MsgBox "Results have been filtered."
>
>
> End If
>
> End Sub
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Message Box to Display a count of Records Michael Microsoft Access VBA Modules 3 5th Apr 2010 07:09 PM
Count filtered records =?Utf-8?B?R2xlbm4gU3VnZ3M=?= Microsoft Access Form Coding 1 19th Jul 2006 01:44 PM
How can the count of filtered records always display? =?Utf-8?B?Um9iZXJ0IEJ1c2htYW4=?= Microsoft Excel Worksheet Functions 1 2nd Nov 2005 09:11 PM
Count Filtered Records Pat Mattimoe Microsoft Excel Misc 2 17th Dec 2003 12:17 PM
Count filtered records Unnur U Microsoft Access Form Coding 4 3rd Sep 2003 04:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:38 PM.