PC Review


Reply
Thread Tools Rate Thread

Changing rowsource based on checkbox

 
 
=?Utf-8?B?TmF0aGFuIFdvbGZl?=
Guest
Posts: n/a
 
      10th Jul 2007
I have a combo box ,cboLocations, where the rowsource is only active
locations, qryActiveLocations. I want to be able to use a checkbox to set the
rowsource of cboLocations to either active locations only
(qryActiveLocations) or all Locations (tblLocationNames). What I've tried to
do is is use an If Then statement in the cboLocations On Click event to set
the rowsource, but then cboLocations is empty when I click in it.

Private Sub cboLocation_Click()
If chkActive = True Then
Me.cboLocation.RowSource = qryActiveLocationstest
Me.cboLocation.Requery
Else:
Me.cboLocation.RowSource = tblLocationNames
Me.cboLocation.Requery
End If
End Sub

What am I doing wrong? Thanks for any help.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFja2llIEw=?=
Guest
Posts: n/a
 
      10th Jul 2007
Sounds like that code should be on the After Update event of your chkActive
control instead of the On Click of your combo box.

Another option would be to leave the control source the same for the combo
box (use the query) and set up hidden criteria fields on your form based on
the chkActive field. Use an unbound, hidden text box
EndStatus: IIF([chkActive]=true,"A","Z")

Then on your query criteria line for your location status put:
Between "A" and Forms!frmFormName!EndStatus

(This example uses "A" for active status, your query and unbound field would
have to take into account how your data is set up)

Hope this helps.
Jackie

"Nathan Wolfe" wrote:

> I have a combo box ,cboLocations, where the rowsource is only active
> locations, qryActiveLocations. I want to be able to use a checkbox to set the
> rowsource of cboLocations to either active locations only
> (qryActiveLocations) or all Locations (tblLocationNames). What I've tried to
> do is is use an If Then statement in the cboLocations On Click event to set
> the rowsource, but then cboLocations is empty when I click in it.
>
> Private Sub cboLocation_Click()
> If chkActive = True Then
> Me.cboLocation.RowSource = qryActiveLocationstest
> Me.cboLocation.Requery
> Else:
> Me.cboLocation.RowSource = tblLocationNames
> Me.cboLocation.Requery
> End If
> End Sub
>
> What am I doing wrong? Thanks for any help.

 
Reply With Quote
 
Mr. B
Guest
Posts: n/a
 
      10th Jul 2007
On Jul 10, 11:46 am, Jackie L <Jack...@discussions.microsoft.com>
wrote:
> Sounds like that code should be on the After Update event of your chkActive
> control instead of the On Click of your combo box.
>
> Another option would be to leave the control source the same for the combo
> box (use the query) and set up hidden criteria fields on your form based on
> the chkActive field. Use an unbound, hidden text box
> EndStatus: IIF([chkActive]=true,"A","Z")
>
> Then on your query criteria line for your location status put:
> Between "A" and Forms!frmFormName!EndStatus
>
> (This example uses "A" for active status, your query and unbound field would
> have to take into account how your data is set up)
>
> Hope this helps.
> Jackie
>
>
>
> "Nathan Wolfe" wrote:
> > I have a combo box ,cboLocations, where the rowsource is only active
> > locations, qryActiveLocations. I want to be able to use a checkbox to set the
> > rowsource of cboLocations to either active locations only
> > (qryActiveLocations) or all Locations (tblLocationNames). What I've tried to
> > do is is use an If Then statement in the cboLocations On Click event to set
> > the rowsource, but then cboLocations is empty when I click in it.

>
> > Private Sub cboLocation_Click()
> > If chkActive = True Then
> > Me.cboLocation.RowSource = qryActiveLocationstest
> > Me.cboLocation.Requery
> > Else:
> > Me.cboLocation.RowSource = tblLocationNames
> > Me.cboLocation.Requery
> > End If
> > End Sub

>
> > What am I doing wrong? Thanks for any help.- Hide quoted text -

>
> - Show quoted text -


Normally I would use a group control to allow the user to select the
option for the critera of which recordset is to be returned. I would
create a group control and and one option button for "Active"
locations and one for "All location". (Note, here you could actually
have three options by adding the "Inactive" option.) then use the
After Update event of the Group control to make the changes to the
record source of you combo box.

HTH

Mr B

 
Reply With Quote
 
=?Utf-8?B?TmF0aGFuIFdvbGZl?=
Guest
Posts: n/a
 
      11th Jul 2007
Thank you both for answering. Unfortunately, for some reason no matter what
solution I try, when I click in the combo box, there are no locations.

"Mr. B" wrote:

> On Jul 10, 11:46 am, Jackie L <Jack...@discussions.microsoft.com>
> wrote:
> > Sounds like that code should be on the After Update event of your chkActive
> > control instead of the On Click of your combo box.
> >
> > Another option would be to leave the control source the same for the combo
> > box (use the query) and set up hidden criteria fields on your form based on
> > the chkActive field. Use an unbound, hidden text box
> > EndStatus: IIF([chkActive]=true,"A","Z")
> >
> > Then on your query criteria line for your location status put:
> > Between "A" and Forms!frmFormName!EndStatus
> >
> > (This example uses "A" for active status, your query and unbound field would
> > have to take into account how your data is set up)
> >
> > Hope this helps.
> > Jackie
> >
> >
> >
> > "Nathan Wolfe" wrote:
> > > I have a combo box ,cboLocations, where the rowsource is only active
> > > locations, qryActiveLocations. I want to be able to use a checkbox to set the
> > > rowsource of cboLocations to either active locations only
> > > (qryActiveLocations) or all Locations (tblLocationNames). What I've tried to
> > > do is is use an If Then statement in the cboLocations On Click event to set
> > > the rowsource, but then cboLocations is empty when I click in it.

> >
> > > Private Sub cboLocation_Click()
> > > If chkActive = True Then
> > > Me.cboLocation.RowSource = qryActiveLocationstest
> > > Me.cboLocation.Requery
> > > Else:
> > > Me.cboLocation.RowSource = tblLocationNames
> > > Me.cboLocation.Requery
> > > End If
> > > End Sub

> >
> > > What am I doing wrong? Thanks for any help.- Hide quoted text -

> >
> > - Show quoted text -

>
> Normally I would use a group control to allow the user to select the
> option for the critera of which recordset is to be returned. I would
> create a group control and and one option button for "Active"
> locations and one for "All location". (Note, here you could actually
> have three options by adding the "Inactive" option.) then use the
> After Update event of the Group control to make the changes to the
> record source of you combo box.
>
> HTH
>
> Mr B
>
>

 
Reply With Quote
 
Bob Quintal
Guest
Posts: n/a
 
      11th Jul 2007
=?Utf-8?B?TmF0aGFuIFdvbGZl?=
<(E-Mail Removed)> wrote in
news:2EFDA6E4-965F-4A67-8B6E-(E-Mail Removed):

> Thank you both for answering. Unfortunately, for some reason
> no matter what solution I try, when I click in the combo box,
> there are no locations.
>

One issue with changing the rowsource of a combobox is that all
possible row sources should have the same fields presented, in
the same sequence. If, for example, your query returns the
columns [LocationID], [location Name] then your table should
also have [LocationID], [location Name] as its first two
columns.



> "Mr. B" wrote:
>
>> On Jul 10, 11:46 am, Jackie L
>> <Jack...@discussions.microsoft.com> wrote:
>> > Sounds like that code should be on the After Update event
>> > of your chkActive control instead of the On Click of your
>> > combo box.
>> >
>> > Another option would be to leave the control source the
>> > same for the combo box (use the query) and set up hidden
>> > criteria fields on your form based on the chkActive field.
>> > Use an unbound, hidden text box EndStatus:
>> > IIF([chkActive]=true,"A","Z")
>> >
>> > Then on your query criteria line for your location status
>> > put: Between "A" and Forms!frmFormName!EndStatus
>> >
>> > (This example uses "A" for active status, your query and
>> > unbound field would have to take into account how your data
>> > is set up)
>> >
>> > Hope this helps.
>> > Jackie
>> >
>> >
>> >
>> > "Nathan Wolfe" wrote:
>> > > I have a combo box ,cboLocations, where the rowsource is
>> > > only active locations, qryActiveLocations. I want to be
>> > > able to use a checkbox to set the rowsource of
>> > > cboLocations to either active locations only
>> > > (qryActiveLocations) or all Locations (tblLocationNames).
>> > > What I've tried to do is is use an If Then statement in
>> > > the cboLocations On Click event to set the rowsource, but
>> > > then cboLocations is empty when I click in it.
>> >
>> > > Private Sub cboLocation_Click()
>> > > If chkActive = True Then
>> > > Me.cboLocation.RowSource = qryActiveLocationstest
>> > > Me.cboLocation.Requery
>> > > Else:
>> > > Me.cboLocation.RowSource = tblLocationNames
>> > > Me.cboLocation.Requery
>> > > End If
>> > > End Sub
>> >
>> > > What am I doing wrong? Thanks for any help.- Hide quoted
>> > > text -
>> >
>> > - Show quoted text -

>>
>> Normally I would use a group control to allow the user to
>> select the option for the critera of which recordset is to be
>> returned. I would create a group control and and one option
>> button for "Active" locations and one for "All location".
>> (Note, here you could actually have three options by adding
>> the "Inactive" option.) then use the After Update event of
>> the Group control to make the changes to the record source of
>> you combo box.
>>
>> HTH
>>
>> Mr B
>>
>>

>




--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

 
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
Changing the rowsource of a combo box Bill Murphy Microsoft Access Forms 5 19th Mar 2007 03:52 PM
Changing the rowsource of a combo box Bill Murphy Microsoft Access Form Coding 5 19th Mar 2007 03:52 PM
changing cbo rowsource Junior Microsoft Access Form Coding 1 25th Oct 2005 03:24 PM
MS Access - Changing content of a calculated field based on value of checkbox-Help! aaldridge Windows XP 3 20th Jun 2005 06:51 AM
CheckBox: Changing Only Checkbox not Text Backcolor =?Utf-8?B?TWFyaw==?= Microsoft Dot NET Framework Forms 0 29th Apr 2004 05:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:16 AM.