PC Review


Reply
Thread Tools Rate Thread

Displaying Matching Records from Combo Boxes

 
 
=?Utf-8?B?SW50cmVwaWRfWWVsbG93?=
Guest
Posts: n/a
 
      11th Oct 2006
I have a form with two Combo Boxes to filter data when the open form button
is pressed. The code below only works when i choose an option from both combo
boxes... i want to be able to choose no options or one option from either.
any help would be appreciated. thanks.

Private Sub btnCompanyManagement_Click()
On Error GoTo Err_btnCompanyManagement_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmCompany_Management"

stLinkCriteria = "[Status]=" & "'" & Me![cmbStatus] & "'"
stLinkCriteria = "[Account_Manager]=" & "'" & Me![cmbAccount_Manager] &
"'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnCompanyManagement_Click:
Exit Sub

Err_btnCompanyManagement_Click:
MsgBox Err.Description
Resume Exit_btnCompanyManagement_Click

End Sub

 
Reply With Quote
 
 
 
 
Graham Mandeno
Guest
Posts: n/a
 
      11th Oct 2006
Hi Intrepid

The code you have shown us will filter only on [Account_Manager] and ignore
[Status].

You need something like this:

If Not IsNull(cmbStatus) Then
stLinkCriteria = "[Status]=" & "'" & Me![cmbStatus] & "'"
End If
If Not IsNull(cmbAccount_Manager) Then
If Len(stCriteria) > 0 then stCriteria = stCriteria & " and "
stLinkCriteria = stCriteria & "[Account_Manager]=" _
& "'" & Me![cmbAccount_Manager] & "'"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria

This will add filter criteria to the stCriteria string only if the combo
boxes are not Null (i.e. have a value selected).
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Intrepid_Yellow" <(E-Mail Removed)> wrote in
message news:3A304745-32A2-43E2-88B7-(E-Mail Removed)...
>I have a form with two Combo Boxes to filter data when the open form button
> is pressed. The code below only works when i choose an option from both
> combo
> boxes... i want to be able to choose no options or one option from either.
> any help would be appreciated. thanks.
>
> Private Sub btnCompanyManagement_Click()
> On Error GoTo Err_btnCompanyManagement_Click
>
> Dim stDocName As String
> Dim stLinkCriteria As String
>
> stDocName = "frmCompany_Management"
>
> stLinkCriteria = "[Status]=" & "'" & Me![cmbStatus] & "'"
> stLinkCriteria = "[Account_Manager]=" & "'" & Me![cmbAccount_Manager] &
> "'"
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> Exit_btnCompanyManagement_Click:
> Exit Sub
>
> Err_btnCompanyManagement_Click:
> MsgBox Err.Description
> Resume Exit_btnCompanyManagement_Click
>
> End Sub
>



 
Reply With Quote
 
=?Utf-8?B?SW50cmVwaWRfWWVsbG93?=
Guest
Posts: n/a
 
      13th Oct 2006
Hi,

That would have worked great. Thanks.

But I changed it over to use QueryDef instead and have it all working now.
But thank you still.

IY.

"Graham Mandeno" wrote:

> Hi Intrepid
>
> The code you have shown us will filter only on [Account_Manager] and ignore
> [Status].
>
> You need something like this:
>
> If Not IsNull(cmbStatus) Then
> stLinkCriteria = "[Status]=" & "'" & Me![cmbStatus] & "'"
> End If
> If Not IsNull(cmbAccount_Manager) Then
> If Len(stCriteria) > 0 then stCriteria = stCriteria & " and "
> stLinkCriteria = stCriteria & "[Account_Manager]=" _
> & "'" & Me![cmbAccount_Manager] & "'"
> End If
> DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> This will add filter criteria to the stCriteria string only if the combo
> boxes are not Null (i.e. have a value selected).
> --
> Good Luck!
>
> Graham Mandeno [Access MVP]
> Auckland, New Zealand
>
> "Intrepid_Yellow" <(E-Mail Removed)> wrote in
> message news:3A304745-32A2-43E2-88B7-(E-Mail Removed)...
> >I have a form with two Combo Boxes to filter data when the open form button
> > is pressed. The code below only works when i choose an option from both
> > combo
> > boxes... i want to be able to choose no options or one option from either.
> > any help would be appreciated. thanks.
> >
> > Private Sub btnCompanyManagement_Click()
> > On Error GoTo Err_btnCompanyManagement_Click
> >
> > Dim stDocName As String
> > Dim stLinkCriteria As String
> >
> > stDocName = "frmCompany_Management"
> >
> > stLinkCriteria = "[Status]=" & "'" & Me![cmbStatus] & "'"
> > stLinkCriteria = "[Account_Manager]=" & "'" & Me![cmbAccount_Manager] &
> > "'"
> > DoCmd.OpenForm stDocName, , , stLinkCriteria
> >
> > Exit_btnCompanyManagement_Click:
> > Exit Sub
> >
> > Err_btnCompanyManagement_Click:
> > MsgBox Err.Description
> > Resume Exit_btnCompanyManagement_Click
> >
> > 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
displaying reports via list boxes or combo boxes =?Utf-8?B?d2lubmll?= Microsoft Access Reports 3 17th Apr 2006 10:04 AM
displaying times in combo boxes =?Utf-8?B?TEhhcm8=?= Microsoft Excel Programming 1 17th Jun 2005 07:17 PM
Synchronizing Multiple Combo boxes to view matching data on a Form =?Utf-8?B?TWFyayBTZW5pYmFsZGk=?= Microsoft Access Forms 2 16th Jun 2004 07:42 PM
Combo Boxes displaying Reports Louisa Wilde Microsoft Access Forms 1 27th Oct 2003 12:51 PM
Text/Combo Boxes displaying columns from records in specific tables Brendan Irwin Microsoft Access Forms 2 1st Oct 2003 01:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:28 AM.