PC Review


Reply
Thread Tools Rate Thread

Combo Box - Enable = False if no records

 
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      7th Nov 2007
Hi,

Does anyone know how to test for records in a combobox and, if there are
none, set enabled to false. I would like the user to not fool with the
element if it doesn't apply to the part they have selected.

Here is the code I am using to filter the records in the combo boxes
(cascading).

Me.Text2.RowSource = "Select distinct parts.width " & _
"FROM parts " & _
"WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
"ORDER BY parts.width;"

Me.Text4.RowSource = "Select distinct parts.length " & _
"FROM parts " & _
"WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
"ORDER BY parts.length;"

Me.Text6.RowSource = "Select distinct parts.height " & _
"FROM parts " & _
"WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
"ORDER BY parts.height;"

Thanks in advance.

 
Reply With Quote
 
 
 
 
fredg
Guest
Posts: n/a
 
      8th Nov 2007
On Wed, 7 Nov 2007 13:41:01 -0800, Bonnie wrote:

> Hi,
>
> Does anyone know how to test for records in a combobox and, if there are
> none, set enabled to false. I would like the user to not fool with the
> element if it doesn't apply to the part they have selected.
>
> Here is the code I am using to filter the records in the combo boxes
> (cascading).
>
> Me.Text2.RowSource = "Select distinct parts.width " & _
> "FROM parts " & _
> "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> "ORDER BY parts.width;"
>
> Me.Text4.RowSource = "Select distinct parts.length " & _
> "FROM parts " & _
> "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> "ORDER BY parts.length;"
>
> Me.Text6.RowSource = "Select distinct parts.height " & _
> "FROM parts " & _
> "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> "ORDER BY parts.height;"
>
> Thanks in advance.


Code the Form's Current event:
MeText2.Enabled = Me.Text2.ListCount > 0
You also will have to place the same code in whatever combo's
AfterUpdate event changes the Text2 rowsource.

Do the same for the other combo boxes.

You might want to consider using a different name for your combo
boxes. Text is usually associated with a text control. Also it should
be more meaningful to someone who may try to modify your database in
the future. Perhaps something like "cboWidth", etc.

In addition, Width and Height are reserved Access/VBA words and should
not be used as field names.
For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

For an even more complete list of reserved words, see:
http://www.allenbrowne.com/Ap****ueBadWord.html

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      8th Nov 2007
Thanks Fred. I actually tried this but maybe I was doing something wrong.
I'll give it another go and change my reserved words.

Appreciate the help.

Bonnie

"fredg" wrote:

> On Wed, 7 Nov 2007 13:41:01 -0800, Bonnie wrote:
>
> > Hi,
> >
> > Does anyone know how to test for records in a combobox and, if there are
> > none, set enabled to false. I would like the user to not fool with the
> > element if it doesn't apply to the part they have selected.
> >
> > Here is the code I am using to filter the records in the combo boxes
> > (cascading).
> >
> > Me.Text2.RowSource = "Select distinct parts.width " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.width;"
> >
> > Me.Text4.RowSource = "Select distinct parts.length " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.length;"
> >
> > Me.Text6.RowSource = "Select distinct parts.height " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.height;"
> >
> > Thanks in advance.

>
> Code the Form's Current event:
> MeText2.Enabled = Me.Text2.ListCount > 0
> You also will have to place the same code in whatever combo's
> AfterUpdate event changes the Text2 rowsource.
>
> Do the same for the other combo boxes.
>
> You might want to consider using a different name for your combo
> boxes. Text is usually associated with a text control. Also it should
> be more meaningful to someone who may try to modify your database in
> the future. Perhaps something like "cboWidth", etc.
>
> In addition, Width and Height are reserved Access/VBA words and should
> not be used as field names.
> For additional reserved words, see the Microsoft KnowledgeBase article
> for your version of Access:
>
> 109312 'Reserved Words in Microsoft Access' for Access 97
> 209187 'ACC2000: Reserved Words in Microsoft Access'
> 286335 'ACC2002: Reserved Words in Microsoft Access'
> 321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'
>
> For an even more complete list of reserved words, see:
> http://www.allenbrowne.com/Ap****ueBadWord.html
>
> --
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
>

 
Reply With Quote
 
=?Utf-8?B?Qm9ubmll?=
Guest
Posts: n/a
 
      8th Nov 2007
Hi Fred,

Not sure why but (there is nothing in this field) - when I check it in the
Immediate Window, the ListCount is 1 when I check:
?FORMS.FORM1.TEXT6.listcount

but also says NULL if I just check: forms!form1!text6

So the control stays enabled.

Any ideas?

Bonnie

Thanks.



"fredg" wrote:

> On Wed, 7 Nov 2007 13:41:01 -0800, Bonnie wrote:
>
> > Hi,
> >
> > Does anyone know how to test for records in a combobox and, if there are
> > none, set enabled to false. I would like the user to not fool with the
> > element if it doesn't apply to the part they have selected.
> >
> > Here is the code I am using to filter the records in the combo boxes
> > (cascading).
> >
> > Me.Text2.RowSource = "Select distinct parts.width " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.width;"
> >
> > Me.Text4.RowSource = "Select distinct parts.length " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.length;"
> >
> > Me.Text6.RowSource = "Select distinct parts.height " & _
> > "FROM parts " & _
> > "WHERE parts.ItemDesc = '" & descrip.Value & "' " & _
> > "ORDER BY parts.height;"
> >
> > Thanks in advance.

>
> Code the Form's Current event:
> MeText2.Enabled = Me.Text2.ListCount > 0
> You also will have to place the same code in whatever combo's
> AfterUpdate event changes the Text2 rowsource.
>
> Do the same for the other combo boxes.
>
> You might want to consider using a different name for your combo
> boxes. Text is usually associated with a text control. Also it should
> be more meaningful to someone who may try to modify your database in
> the future. Perhaps something like "cboWidth", etc.
>
> In addition, Width and Height are reserved Access/VBA words and should
> not be used as field names.
> For additional reserved words, see the Microsoft KnowledgeBase article
> for your version of Access:
>
> 109312 'Reserved Words in Microsoft Access' for Access 97
> 209187 'ACC2000: Reserved Words in Microsoft Access'
> 286335 'ACC2002: Reserved Words in Microsoft Access'
> 321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'
>
> For an even more complete list of reserved words, see:
> http://www.allenbrowne.com/Ap****ueBadWord.html
>
> --
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail
>

 
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
Enable Combo box based on value in check box and list box.... M G Henry Microsoft Excel Discussion 0 22nd Oct 2008 07:32 PM
VBA always creates linked chart even when using PasteExcelTable False, False, False in Office 2007 Matt Simpson Microsoft Excel Programming 0 6th Aug 2007 08:11 PM
Enable Combo Box based on Selection of 1st Combo box =?Utf-8?B?R2Vvcmdl?= Microsoft Access Form Coding 3 24th Apr 2007 04:34 PM
$C$1972,2,FALSE, $C$1972,3,FALSE is ok, But $C$1972,4,FALSE Give # =?Utf-8?B?U3RldmVk?= Microsoft Excel Worksheet Functions 6 3rd Jul 2006 01:49 AM
Combo Box - Hide Combo Box w/Check Box =?Utf-8?B?UGF1bA==?= Microsoft Excel Programming 5 3rd Dec 2004 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 PM.