Solved

MS Access 2007 VBA Select Case Help

Posted on 2010-11-23
6
933 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TypeError: Users.save is not a function 3 40
ms access 2013, running .mdb 2 31
Error in Rs.MoveNext & Duplication of Record 14 26
use lov values 2 33
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…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

920 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

15 Experts available now in Live!

Get 1:1 Help Now