Solved

MS Access 2007 VBA Select Case Help

Posted on 2010-11-23
6
937 Views
Last Modified: 2012-05-10
This select case isn't recognizing when Me.Status.Text meets the conditions.  Everything is meeting only the Select Else, which is incorrect.  Do you see my error?  Thanks.

Option Compare Database
Option Explicit

Dim lngRed As Long
Dim lngYellow As Long
Dim lngGreen As Long
Dim lngWhite As Long

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
lngRed = RGB(207, 123, 121)  'Red
lngYellow = RGB(255, 255, 0) 'Yellow
lngGreen = RGB(143, 188, 143) 'Dark See Green
lngWhite = RGB(255, 255, 255)   'White


Select Case Status.BackColor
Case Me.Status.Text = "-P"
    Me.Status.BackColor = lngRed
Case Me.Status.Text = "MP"
    Me.Status.BackColor = lngYellow
Case Me.Status.Text = "+P"
    Me.Status.BackColor = lngGreen
Case Else
    Me.Status.BackColor = lngWhite

End Select

End Sub
0
Comment
Question by:ReneeM787
6 Comments
 
LVL 16

Expert Comment

by:Ady Foot
ID: 34197786
Your Select Case statement is case sensitive at the moment - could that be the problem?  At present you are literally trying to match the value "-P".  If the Text field contains anything else at all then the match will fail.  If that's the case you need to use Me.Status.Text.StartsWith or similar.

What type of control is 'Stutus' anyhow?
0
 
LVL 16

Expert Comment

by:Ady Foot
ID: 34197802
What you can try to do is use a message box to show you exactly what Me.Status.Text is set to when it fails to match.  There could be a space getting in there somewhere (or similar).
0
 
LVL 7

Accepted Solution

by:
shaydie earned 250 total points
ID: 34197830
I think you want this:

Select Case Me.Status.Text

Case  "-P"
    Me.Status.BackColor = lngRed
Case  "MP"
    Me.Status.BackColor = lngYellow
Case "+P"
    Me.Status.BackColor = lngGreen
Case Else
    Me.Status.BackColor = lngWhite

End Select
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 16

Expert Comment

by:Ady Foot
ID: 34197841
Ha - I didn't even spot that mistake shaydie.  Well done that man - I think that'll get it sorted.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 34197885
A couple of points.  Your case statement starts out with me.Status.BackColor, and then changes to me.Status.Text.  If you want to check the text property (or Value) of the Status control then try:

Select Case me.Status Text
    Case "-P"
        Me.Status.BackColor = lngRed
    Case "MP"
        Me.Status.BackColor = lngYellow
    Case "+P"
        Me.Status.BackColor = lngGreen
    Case Else
        Me.Status.BackColor = lngWhite
End Select

Also, is Status actually a text field, or is it a combo box?  If a combo box, is the bound column the column that contains the text string, or is it a numeric?  If a combo, and the text is not in the bound column, you will need to use something like:

SELECT CASE me.Status.Column(2)

Another point.  If you only have a couple of status codes, you could just use conditional formatting for this.

0
 

Author Closing Comment

by:ReneeM787
ID: 34223171
Thank you!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Report Expression 4 25
Find unused columns in a table 12 67
Special characters in a TCPDF 4 23
Access table not showing correct column 6 18
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question