vba conditional formatting
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page
 
view a printable version of this pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » VBA conditional formatting

VBA conditional formatting

resolvedResolved · Urgent Priority · Version 2003

replyReplySun 28 Feb 2010, 19:21Delegate David said...

VBA conditional formatting

Hi. I've put the code below in to my form and the ID field formats red, green and yellow fine, however, the time_limit field is purely red. Is it not possible to use dynamic conditional formatting in vba or is there something wrong with my code? Thanks. David.

Private Sub Form_Load()

Dim objFrc As FormatCondition

'delete existing formats
Me.ID.FormatConditions.Delete
Me.TIME_LIMIT.FormatConditions.Delete

'create three format objects and add them to the FormatConditions collection
Set objFrc = Me!ID.FormatConditions.Add(acFieldValue, acLessThan, 4)
Set objFrc = Me!ID.FormatConditions.Add(acFieldValue, acEqual, 4)
Set objFrc = Me!ID.FormatConditions.Add(acFieldValue, acGreaterThan, 4)

'create three format objects and add them to the FormatConditions collection
Set objFrc = Me!TIME_LIMIT.FormatConditions.Add(acFieldValue, acLessThan, DATE)
Set objFrc = Me!TIME_LIMIT.FormatConditions.Add(acFieldValue, acEqual, DATE)
Set objFrc = Me!TIME_LIMIT.FormatConditions.Add(acFieldValue, acGreaterThan, DATE)

'format the time_limit text box with each condition
With Me.ID.FormatConditions(0)
.BackColor = vbGreen
End With

With Me.ID.FormatConditions(1)
.BackColor = vbYellow
End With

With Me.ID.FormatConditions(2)
.BackColor = vbRed
End With

With Me.TIME_LIMIT.FormatConditions(0)
.BackColor = vbGreen
End With

With Me.TIME_LIMIT.FormatConditions(1)
.BackColor = vbYellow
End With

With Me.TIME_LIMIT.FormatConditions(2)
.BackColor = vbRed
End With

End Sub

For upcoming training course dates see: Pricing & availability

replyReplyWed 3 Mar 2010, 09:46Trainer Stephen said...

RE: VBA conditional formatting

Hi David

Thank you for your question.

This question is rather hard to answer without seeing the database in question.
One possibility would be to run your code from the form's load method rather than the open method.
If this doesn't work please let me know, and I will explore other possibilities.

Regards

Stephen

replyReplyWed 3 Mar 2010, 09:47Trainer Stephen said...

RE: VBA conditional formatting

Hi David

Thank you for your question.

This question is rather hard to answer without seeing the database in question.
One possibility would be to run your code from the form's load method rather than the open method.
If this doesn't work please let me know, and I will explore other possibilities.

Regards

Stephen

replyReplyWed 3 Mar 2010, 18:09Delegate David said...

RE: VBA conditional formatting

Hi Stephen

Thanks for looking into this for me. I've used both on open and on load method but both produce the same results.

In terms of the db; its actually just a test db to test the conditional formatting before I apply it to the main db. The table the form is looking at is 2 columns by 7 rows. Column 1 is the ID (1-7) and column 2 is a date field containing 7 dates that are around DATE, even to the extreme of one at 1974 and one at 2020.

As stated, the ID formatting works on the threshold of 4 in the code but the date is purely red.

Thanks

David

replyReplyWed 3 Mar 2010, 19:03Delegate David said...

RE: VBA conditional formatting

Hi Stephen

I've had time to play around with this now, it looks like the conditional formatting is based on numbers only so I've done a CLng(DATE) to get the 40240 for today and the date field is now formatting red, yellow and green.

Thanks for your time on this one.

Regards

David

 

 

Please browse our web site to find out more about
access.training and other Microsoft training courses.

Access tip:

Change The Default Font in Access 2003

You can change the default font in Access 2003 so that whenever you create a new database your preferred font is automatically set.

To change the default font:

1.From the menu bar select Tools.
2.Click Options.
3.Go to the Datasheet tab:
4.In the Default font section select your preferred font from the list of fonts e.g. Arial.
5.Select your preferred size from the size menu e.g. 12.
6.Click Apply.

Click on the Tables/queries tab:
1.In the Query Design font section select your preferred font from the list of fonts e.g. Arial.
2.Select your preferred size from the size menu e.g. 12.
3.Click Apply.
4.Click OK.

The default font for Access has now been changed.

View all Access hints and tips

forum postCould you explain in simple terms how the logarithmic scale (in charting) is calculated and when it is most appropriate to use?

» Forum post: Excel


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Management training

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

Training venues London
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

Access courses
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training