Need some help.

Degalle

New member
Local time
Today, 15:54
Joined
Dec 2, 2008
Messages
3
I'm pretty sure this goes in here but if not admins please move to Access General Discussion.


So we all know access has conditional formating but it only allows 3 and I've looked all over for any sample coding or anything I could use but it doesn't allow me to change the Backcolor of the Text box/Combo Box on the form when it's a Continuous Form unless it's in conditional formatting but I'm not sure what I'm doing wrong or where I need to start.

Private Sub Form_Load()
Company.SetFocus
If Me.Company.Text = "COP" Then
Me.Company.BackColor = RGB(255, 0, 0)
End If
End Sub

I know this would normally work on VBA for forms but this is Access and seems hard for VBA and it's something that would be very nice.

Please let me know, I've heard "Expression Is" but didn't find anything on that, I'm not sure if I can create a conditional format let it run and then delete it and add a new one (Figured it would just remove the other one and create the new one).

Thanks guys and sorry if this seems a newbish question I am new but I really want to learn.

Degalle
 
Expression is...
You fill in a "True/False" formala in the textbox behind it. to work with other fields than the one you are putting the CF on.

Value is
Requires a value for the field that you are applying the CF on.

In this case looks like you are looking for "Value is" then in the textbox: "COP"

Good luck!

P.S. Welcome to (one of ;)) the best Access forums on the Internet.
 
So this is in VBA right so my code would be something like this right?

Private Sub Form_Load()
If Company.Value = "COP" Then
Company.BackColor = vbRed
End If
End Sub


I'm still a little lost I guess, do I needing the "If...Then" Statement or is "Value is" it's own built in vba?

Thanks again I'm glad I joined up and this seems like a great forum.

Sorry again if I sound/am a newb I'll admit it lol.

Degalle
 
For what you want to do you will need to do it through Conditional Formating. How many specific Conditions do you want to deal with?

Conditional Formating can also be set with Code but it can get quite involved if you want to go beyond the current three conditions available to set.

Changing the color via code as you have illustrated will change the Background color of the Company TextBox throughout he entire Continuous Form for all records.
.
 
I'm looking at many with additionals. So basically the user will be putting in the data with the colors they select and then it'll automatically set the conditional formatting since that does seem to be the only way. So the answer is for now a lot since I know we will have many companys.

I know a little of vba conditional formatting but I'm still unsure I guess of how to go about it to allow it to change the background color with each different company name.

Thanks again.

Degalle
 
Conditional formatting is found in the menu (if you are inside the design of a form)
Format > Conditional formatting

In this you are limitted to 4 different formats, though you can set theoriticaly unlimitted AND and OR statements...
I.e. You can have default (1) white background
2) Red
3) Yellow
4) Orange
Thats it... But you can have
i.e. "Stop" or "No Go" or "Barred" or "Forbidden"
in the criteria for Red, so as long as you only want 4 different formats... you are good to go.

More formats are basicaly impossible if you have a tabular form (showing more than one record on the screen)

If you have form view with only one record visible you can use code like
If Company.Value = "COP" Then
Company.BackColor = vbRed
End If
But if you have many different ones maybe making a table with these formats so you can more easily change them, instead of fiddling with the code.
 

Users who are viewing this thread

Back
Top Bottom