Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / August 2005

Tip: Looking for answers? Try searching our database.

Use "Like" function in  conditional formatting on form.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daveo - 21 Jul 2005 06:09 GMT
Hi folks,

Is it possible to use the "Like" function in an expression for a
conditional formatting rule.

e.g.
Like "*" & [Forms]![myform].[myfield] & "*"

I have a field that always contains either value X or value Y but has
additional information concatenated onto it that changes, and I would
like the field to be blue for value X and green for value Y.

Thanks - David
Wolfgang Kais - 21 Jul 2005 12:50 GMT
Hello David.

> Is it possible to use the "Like" function in an expression
> for a conditional formatting rule.
[quoted text clipped - 4 lines]
> additional information concatenated onto it that changes, and I would
> like the field to be blue for value X and green for value Y.

Should be possible, using "expression is" and an expression like:
[myfield] Like "*X*"

Signature

Regards,
Wolfgang

Philo Hamel - 21 Jul 2005 13:12 GMT
Hi David,

I don't think you need the Like function to change the format, you need to
determine the value in the field and then change the color accordingly. I
hope this is what your looking for.

Private Sub Form_Current()

   If Left(Me.txtField, 1) = "x" Then
       Me.txtField.ForeColor = RGB(0, 0, 255)
   ElseIf Left(Me.txtField, 1) = "y" Then
       Me.txtField.ForeColor = RGB(0, 255, 0)
   Else
       Me.txtField.ForeColor = RGB(0, 0, 0)
   End If

End Sub

Note that:
- You need to replace [txtField] with your own field's name;
- The text color is changed with this, to change the background color you
need to use BackColor;
- You can also put this code in the in the AfterUpdate event of your text
field.

Good luck,
Philo

>Hi folks,
>
[quoted text clipped - 9 lines]
>
>Thanks - David
Daveo - 08 Aug 2005 06:25 GMT
Wolfgang - I can't seem to get the syntax right. I'm entering
[txtSatStatus] = Like "*Coen*" and get an invalid syntax error.

Philo - I'll probably go for your option, but need to use the Like
function or similar. E.g. The field may contain "Project X - Coen" or
"Coen - XXXXXX" and I need the field to go a certain colour if any part
of it contains the work "Coen". Could you show me how to modify your
code to do that please?

Thanks for the help - David
Duane Hookom - 09 Aug 2005 05:39 GMT
Remove the "=" when using "Like".

[txtSatStatus] Like "*Coen*"

Signature

Duane Hookom
MS Access MVP

> Wolfgang - I can't seem to get the syntax right. I'm entering
> [txtSatStatus] = Like "*Coen*" and get an invalid syntax error.
[quoted text clipped - 6 lines]
>
> Thanks for the help - David
Daveo - 09 Aug 2005 07:34 GMT
Thanks Duane - after hours of fiddling I tried that and it worked!!

David
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.