Select Case question - Comparing strings

I am passing variables into a subroutine, and comparing these to some
parameters in a array.  If all 4 of the variables passed in are equal to 4
values in the array, I run a a loop adding values to the array.

I can make a series of If..Then statements work but cannot get the equivalent
Select case statements to work.

I am attaching the entire subroutine;

Any suggestions appreciated. 



' --------------------------------------

Sub Add_ClnLoins(idxdate As Variant, _
                    idxSpecies As String, _
                    idxclnshift As String, _
                    dat_start_time As Variant, _
                    hrs As Single, _
                    dat_Clned_Loins As Single, _
                    arr_Hourly_Demand As Variant)

Dim testDate As Date
Dim testTime As Date

Dim i As Integer
Dim iHr As Integer
Dim LoinsPerHr As Single

i = 1
 Do While arr_Hourly_Demand(i, 1) <> ""

testDate = FormatDateTime(arr_Hourly_Demand(i, 1), vbShortDate)
testTime = FormatDateTime(arr_Hourly_Demand(i, 2), vbShortTime)

'*********  This series of statements does NOT work

Select Case Trim(CStr(idxSpecies))
  Case Trim(CStr(idxSpecies)) = CStr(arr_Hourly_Demand(i, 5))
    Select Case Trim(CStr(idxdate))
      Case CStr(idxdate) = CStr(testDate)
        Select Case Trim(CStr(idxclnshift))
          Case CStr(idxclnshift) = CStr(arr_Hourly_Demand(i, 4))
            Select Case Trim(CStr(dat_start_time))
               Case CStr(dat_start_time) = CStr(testTime)
                  For iHr = 1 To hrs

                    arr_Hourly_Demand(i - 1 + iHr, 6) = dat_Clned_Loins / hrs

                  Next iHr

                  End Select
                  End Select
                  End Select
                  End Select

'  ******* The following series of statements work ***************

If idxSpecies = CStr(arr_Hourly_Demand(i, 5)) Then
    If CStr(idxdate) = CStr(testDate) Then
       If CStr(idxclnshift) = CStr(arr_Hourly_Demand(i, 4)) Then
          If CStr(dat_start_time) = CStr(testTime) Then
                  For iHr = 1 To hrs

                  arr_Hourly_Demand(i - 1 + iHr, 6) = dat_Clned_Loins / hrs

                  Next iHr

                  End If
                  End If
                  End If
                  End If

i = i + 1


End Sub

6/5/2010 8:11:36 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 17

Sounds like you misunderstand when to use a Select Case statement.  Use it
when the variable you are examining could contain a wide range of values.  If
you can do what you want with a couple of Ifs, you probably don't need a case
statement.  Case statements really shine when you have lists or ranges of
values that you need to treat together.  This just doesn't sound like one of
those cases.

Message posted via

6/5/2010 9:35:11 PM

Similar Artilces:

lookup link for customer address on account, case, address search
The way the address associations are handled today create tremendous gaps in the structure of CRM records compared to the structure of integrated backoffice financial systems records. What should be trivial integration tasks lead to a LOT of workarounds and customers frustration. Here is how we can improve. Abandon the idea of hardcoding first 2 address records on the account form. Add 2 address lookup fields on the account (relationships) that could be used to select any of the account addresses and expose them on the account form (still show individual address fields on the accoun...

Case 'Actual Duration' not getting updated in SQL
Knowledge Base article 913391: The "Actual Duration" field displays an incorrect value when you view the "Resolve Case" dialog box in Microsoft Dynamics CRM 3.0 This article corrects the time when you resolve a case by adding some script to an onsave event. Here is where it doesnt work: Lets say you go back and change the time from 2 hours to 4 hours on a Service Appointment. The form shows your updated time by running the onsave event but when you resolve the case, you original time displays and not the updated time. I looked in SQL and the ActualDuration and Sc...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at &q...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

SQL question for Great Plains
My users want to email out certain reports to the user group when they are done with their GL activity every week. I have sql scripts for these reports. I am thinking of creating SSIS package with these sql scripts and have the package email out the report. Everything works great so far. The only thing is that I need the users to run this package and they cant have access to the server. The user workstations dont have sql 2005 client installed either. How can I have the users manually trigger start the SSIS package on the server? Has anyone come across this scenario? Thank you. J...

Question About Junk Folder/Mail
When one looks at the Junk Mail folder for either a POP or otherwise server, and does the ongoing Let-Em-In method as follows: 1. Highlight Junk Mail 2. [Right-Click] Junk Mail->Add to Safe Senders list 3. then (on the same message) [Right-Click] Junk Mail->Mark as Not Junk , these two commands certainly work, but one other annoying item is that it assigns the message or messages highlighted as Read. A look in the folder where the [erm] mail rules are supposed to place it shows the message having been processed, but marked as Read, thus not highlighted and fairly dif...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP news:// "GoBonnieGo" <GoB...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Select Case in a Change Event
Hi, I am trying to use a worksheet Change Event to trap changes to specific columns. depending on which column is chnaged by the user, the value in another ciolumn will be altered; so, changes in either column O or P will update column Q, changes in either column T or U will update column V and changes in column Z or AA will update column AB. What I can't figure out is the Select Case bit (where I've got the shouted question below). Here's what I've put together, any comments would be much appreciated. Private Sub Worksheet_Change(ByVal Target As Range) ...

Select Records based another table...
This may be very elementary, but i can't wrap my brain around it. I have tried to dummy it down as much as i can for myself, with plans of adapting it into something working. I have three tables that look like the following: Tbl 1: ProdID A B C 1 $1 $2 $3 2 $4 $5 $6 3 $7 $8 $9 Tbl 2: RmNum ProdID 1 3 1 2 2 1 2 2 Tbl 3: RmNum Style 1 A 2 C Relationships are: [tbl1 ProdID] ------ [tbl2 ProdID] [tbl2 RmNum] ...

Multi-Select List Box Does Not Retain Selected Items
I created an Outlook Form in 2003. But when I select items in the list box they do not remain select when I select another control on the form. Any suggestions? Did you bind the list box to a keywords field? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers "kaykay" <> wrote in message news:276dd01c4638d$bd5af590$a501280a@phx.gbl... > I created an Outlook Form in 2003. But when I select > items i...

Anybody Help with previous question
Hi, I'm getting desperate to solve this, so my apologies for posting this again, but can anybody offer any help with this previous question. If the link doesn't work I have copied the orig question below. I have (been given) the code below that will add a row of 'jobs' to a worksheet named 'Database'. There isa check to see if these jobs have been already added a...

I am very new to VBA and access and have a question regarding a SELECT statement. I am going to run a select (recordset - so I can loop through and process each record) but on my SELECT I want to make sure I return at least 20 rows, otherwise I am going to change my WHERE clause to include more rows. Is there an easy way to do this or do I need to just do an inital SELECT COUNT(*) and then decide which WHERE clause to use?? Do you have an example I can look at? Thank you in advance! AJ On Fri, 14 Dec 2007 17:14:00 -0800, AJ <> wrote: I would not first ...

Check Box Question
I have a user form with several Check Boxes that are for controlling worksheets in a workbook. Each check box is for hiding or unhiding the different worksheets in a workbook from the user form2. Workbook name = Installer Forms Worksheet name = Sheet 1 Checkbox names = Office_Package_Preparations_101 I want when the Box is checked for the worksheet to be shown and when the box is not checked for the worksheet to be hidden. Hi Brian, Important consideration is that you cannot hide all sheets so must test for at least 2 visible sheets before hiding a sheet. If...

DPM 2010 EUR questions
First, sorry if these questions have been asked to death... 1) when using the mobile client with DPM 2010 does the schema extension need to be run to enable users to use the DPM agent to recover local files (ex., from My Documents?) - btw, we're using Win7 x86. 2) if so, does the same rule apply that requires share backups rather than volume backups to allow EUR on client desktops? That is, do i need to backup \\desktop\c$\users\ rather than C:\users\ Thanks. AD schema extension is not required for mobile clients for DPM 2010 EUR. So no possibility of second question....

Drop down list quicker selection
We are using Excel 2003 We created a drop down list using the Data\Validation process, which works fine. When the arrow within a cell is clicked on to show the drop down list, how can you quickly select one of the many names in the list just by typing the first character of a name within the list. At the moment, we have to scroll up and down the list to select a particular name, which in itself isn't a problem, but slows down the process of finding the right name. Can the names within the list be alphabetically grouped when inputting the first character from the keyboard, and spee...

simple question but no answer on any access forum!
I have two tables, table 1 and table 2 (i'll keep this in simple english). Table 1 contains contact details of customers while table two, contains the ID No of the customer from the customer's table and the name from the customers table, plus a load of other info entered by the user as the table is filled (both tables are filled through simple forms). Now, here is my problem. When the user is filling in table 2 from its form, I would like to, after the name is entered, have the ID No auto entered (as its value is in the ID No in the customers table1) into the ID No f...

calendar question...
i set up a calendar with business days listed with a number "1" in the col to the right of the date. i am now trying to return business days only to a list in another sheet. i have done the following: - did a vlookup to pull back dates referenced "JULY". i am trying to search the calendar to pull bacl only the trading days. tried using index, but have to change row number for every cell. also cannot determine with index which dates to pull back...pulls theme all i am looking for the following result: 7/5/2006 7/6/2006 7/7/2006 7/10/2006 7/11/2006 7/12/2006 7/13/20...

Selected fields to update
I need to have the ability, in OL'07, when I try to copy in a contact and am told there is a duplicate, to be able to select which fields I want updated and which not. Is that possible built-in or add-in? -- Boris You may find this of interest - ContactGenie DataPorter 2.0 - specifically handles updating of pre-existing contacts allowing you to define which fields you want to import/update from your input data file (custom forms/fields supported). Features: Download" Karl _...

Change Form/Report Query Based on User Selection
I have a form and report based on a query. I need to change the query based on what the user selects on a form. Using VBA in MS Access 2002, can I change a single field in an existing query from GROUP BY to LAST? This process would be initiated by a click event on a form. Thanks in advance for any help. I would say only if you are willing to construct the entire query string in VBA and then apply that string as the source of the report. John Spencer Access MVP 2002-2005, 2007-2009 The Hilltop Institute University of Maryland Baltimore County Wayne wrote: > I have a form ...