Solved

MS Access 2007 VBA Select Case Help

Posted on 2010-11-23
6
930 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now