Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS Access 2007 VBA Select Case Help

Posted on 2010-11-23
6
Medium Priority
?
952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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 48

Expert Comment

by:Dale Fye
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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