Solved

MS Access 2007 VBA Select Case Help

Posted on 2010-11-23
6
936 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

860 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