473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using Select Case to change ListBox RowSource

stonward
145 100+
Hi Folks,

I have a listbox listing my products. The listbox rowsource changes depending upon the user's selection of exactly which products to list, and in addition there are two pricing structures, trade and retail. I have this working quite well using If Then Else, but there is surely a more elegant solution using Select Case. The following code always jumps to Case Else, although I know thru debug that each case is evaluated and that the correct rowsource query is found. But the source is not being altered. Can you see what is wrong?

Expand|Select|Wrap|Line Numbers
  1. Dim querySource as String
  2. querySource = me.lstProds.RowSource
  3.  
  4. Select Case querySource
  5.        Case "qry_SearchedStockR"
  6.             Debug.Print querySource
  7.             lstProds.RowSource = "qry_searchedStockT"
  8.        Case "qry_AllSearchedR"
  9.             lstProds.Rowsource = "qry_AllSearchedT"
  10.        Case "qryNotTyreR"
  11.             lstProds.RowSource = "qry_NotTyreT"
  12.        Case Else
  13.             Msgbox "Trade Price Not Available in This View."
  14.  
  15. End Select
I have missed out further case statements, debug lines and the turning on/off of labels for the sake of brevity.
Naturally I have tried a number of methods to get this working, but think I'm missing something, um, profound?

Thanks for your time.

Best Regards,

Stonward
Feb 26 '13 #1

✓ answered by Seth Schrock

Then I'm stumped as to why it goes to the Case Else instead of first Case.

9 3006
Seth Schrock
2,965 Expert 2GB
In line 3, put
Expand|Select|Wrap|Line Numbers
  1. Debug.Print querySource
and tell us what it says. It seems strange that your If Then Else worked, but not your Select Case.
Feb 26 '13 #2
stonward
145 100+
Hi Seth.

The immediate window shows the current query underlying the listbox ("qry_SearchedStockR"), which is simply all products in stock and showing Retail price. And it's correct. If I change the listbox query, the Select Case debug statement is always correct. It just doesn't CHANGE the rowsource as it needs to.
Feb 26 '13 #3
Seth Schrock
2,965 Expert 2GB
Then I'm stumped as to why it goes to the Case Else instead of first Case.
Feb 26 '13 #4
stonward
145 100+
Hi Seth,

Ha Ha! That's exactly what i told my user; "Stumped"! Here's the code I'm using at the moment. "Trade Note" is simply a label that says 'Trade Price Only' and I use it's Visible property to gauge which pricing I'm on...

Expand|Select|Wrap|Line Numbers
  1. If lblTradeNote.Visible = False Then
  2. Me.lblTradeNote.Visible = True
  3. Me.cmdPricing.Caption = "Retail Pricing"
  4. If List55.rowSource = "qry_searchedstockR" Then
  5.     List55.rowSource = "qry_searchedstockT"
  6. ElseIf List55.rowSource = "qry_allsearchedR" Then
  7.     List55.rowSource = "qry_allsearchedT"
  8. ElseIf List55.rowSource = "qry_nottyreR" Then
  9.     List55.rowSource = "qry_nottyreT"
  10. Me.cmdPricing.Caption = "Retail Pricing"
  11.  
  12. End If
  13.  
  14. 'if Trade is ON
  15. ElseIf lblTradeNote.Visible = True Then
  16. lblTradeNote.Visible = False
  17. cmdPricing.Caption = "Trade Pricing"
  18. If List55.rowSource = "qry_searchedstockT" Then
  19.     List55.rowSource = "qry_searchedstockR"
  20. ElseIf List55.rowSource = "qry_allsearchedT" Then
  21.     List55.rowSource = "qry_allsearchedR"
  22. ElseIf List55.rowSource = "qry_nottyreT" Then
  23.     List55.rowSource = "qry_nottyreR"
  24. cmdPricing.Caption = "Trade Pricing"
  25.  
  26.  
  27. End If
  28.  
  29. End If
The above works, but does 'strange' things now and again. I got bigger issues at the moment tho...

Thanks for your time.

Regards,

Stonward
Feb 26 '13 #5
zmbd
5,501 Expert Mod 4TB
What you didn't show us was the output from the debug.print statements.
Tad difficult to determine why the Select failed without that information.
Feb 26 '13 #6
stonward
145 100+
Hi ZMBD,

Yeah, no apparent issue. The default query the listbox opens with
"qry_SearchedStockR" is what comes up with debug.print, including adding a debug command at line 3.

Stonward
Feb 27 '13 #7
Seth Schrock
2,965 Expert 2GB
Just an idea, does it literally say qry_SearchedStockR or does it give the SQL code that makes up the query?
Feb 27 '13 #8
zmbd
5,501 Expert Mod 4TB
If you still have the select case code.
If you would please place the debug.print back in at line 3.
Please run the form so the code executes.
<Ctrl><G> to open the immediate window.
Select all of the text that is printed in the immediate window
<ctrl><C>
open a new post in this thread and <ctrl><P>
Something very suspicious going on here... decades of programming and I've never seen a select case fail without cause.
Feb 27 '13 #9
ADezii
8,834 Expert 8TB
If you generated the Row Source by using the Wizard with a Saved Query as the base, then modified it, the Row Source would be a SQL Statement and not the Name of the Query.
Feb 27 '13 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
2
by: TF | last post by:
Hi, Is there any way to change the text color of SOME of the ListBox(Windows Forms Control) items in VB.NET? TF
4
by: Corey | last post by:
I am having some real trouble getting a listbox rowsource to load properly. The listbox is actually on a subform. My main form has several command buttons that change the MASTER_SUB_FORM object...
7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
3
by: Paul Bromley | last post by:
I have just started to use Classes a lot in my code. Often I find that I need to use the same contstructor, but wish to invoke a different action depending on where I am clling the class from. I...
5
by: PJ6 | last post by:
Select Case o.GetType Case = GetType(SomeRandomTypeName) '... End Select Why doesn't this work? Can I make it work or am I stuck with ElseIf for a long list? Paul
11
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
3
by: bpw22az | last post by:
I am currently in the process of setting up an asp page that sends an inquiring student an email regarding his/her application status. The student enters his/her email address on a web page, the...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
11
by: WannabePrgmr | last post by:
In access 2003, on a simple form, I am trying to base the recordsource of a combobox on two other combobox's data. Here is the code I've tried and it did not work (except for the PN Cross/Info). ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.