A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Programtically Setting Conditional Formatting For a Form In Access 2007



 
 
Thread Tools Display Modes
  #1  
Old October 5th, 2009, 06:19 AM posted to microsoft.public.access.forms
Stewart Berman
external usenet poster
 
Posts: 68
Default Programtically Setting Conditional Formatting For a Form In Access 2007

I have a number of sub forms that are displayed in datasheet mode. I need to set the background
color of columns. Unfortunately, if you just do that in design mode it is ignored in datasheet
mode.

However, conditional formatting is not ignored in datasheet mode. You can effectively set the
background column of a datasheet to a value by setting the conditional formatting to expression; the
expression to "1=1" and then the background to whatever you want.

The problem is I need to be able to do it at runtime. I opened the form I want to change in design
mode -- hidden, deleted any conditional formatting they had and tried to set the conditional
formatting for the controls I need to change where the problem arises.

To open the form in design mode:
DoCmd.OpenForm rs.Fields("FormName").Value, acDesign, , , , acHidden
Set frm = Forms(rs.Fields("FormName").Value)
I then walk the form's controls collection looking for the controls to change.

The following code is after I have found the control to change. First I make sure it is a textbox:
If (acTextBox ctl.ControlType) Then
Exit Do
End If
Then I delete any conditional formatting it may have had:
On Error Resume Next
Do While (ctl.formatconditons.Count 0)
ctl.FormatConditions.Item(0).Delete
If (0 Err.Number) Then
Exit Do
End If
ctl.FormatConditions.Refresh
Loop
On Error GoTo 0
Finally I try to add conditional formatting:
ctl.formatconditons.Add acExpression, , "1=1"
ctl.formatconditons.Item(0).BackColor = &H808080
The first line above throws an error: "Object does not support the property or method".

The question is "How do you add conditional formatting via VBA to controls in a form?"

Suggestions anyone?



  #2  
Old October 6th, 2009, 08:39 AM posted to microsoft.public.access.forms
Peter's Software[_2_]
external usenet poster
 
Posts: 8
Default Programtically Setting Conditional Formatting For a Form InAccess 2007

Try this (untested)

ctl.formatconditons.Add acExpression, acNotBetween, 0, 0

Peter De Baets
http://www.peterssoftware.com
  #3  
Old October 6th, 2009, 09:10 PM posted to microsoft.public.access.forms
Stewart Berman
external usenet poster
 
Posts: 68
Default Programtically Setting Conditional Formatting For a Form In Access 2007

I actually did something similar and got it working. I used:
ctl.FormatConditions.Add acExpression, , "1=1"
Should have posted it earlier.


"Peter's Software" wrote:

Try this (untested)

ctl.formatconditons.Add acExpression, acNotBetween, 0, 0

Peter De Baets
http://www.peterssoftware.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.