Reputation: 173
I have a table where the user can select a colour scheme for their database
ID | Colour | SelectedScheme
---|------------|--------------
1 | 136,207,39 | Yes
Then on my form I have the following on the current events tab
Dim RGBcolor As Long
RBGcolor = DLookup("Colour", "SelectedScheme")
Me.boxheader.BackColor = RGB(RGBcolor)
but I'm getting the Argument not optional error. any idea?
Upvotes: 0
Views: 551
Reputation: 97101
The RGB()
function expects 3 numbers, but your code supplies a single string value. That is the cause of the "Argument not optional" compile error.
Construct a new string which includes the RGB()
function plus your string of numbers. Submit that new string to Eval()
...
Me.boxheader.BackColor = Eval("RGB(" & RBGcolor & ")")
Upvotes: 1
Reputation: 49049
The Dlookup function accepts these arguments:
And the RGB functions accepts these three:
I would suggest you to use three different columns for the component color in your table:
ID | ColourR | ColourG | ColourB | SelectedScheme
---|---------|---------|---------|---------------
1 | 136 |207 | 39 | Yes
Your event can be written as this:
Me.boxheader.BackColor = RGB(
DLookup("ColourR", "SchemaTableName", "SelectedScheme=TRUE"),
DLookup("ColourG", "SchemaTableName", "SelectedScheme=TRUE"),
DLookup("ColourB", "SchemaTableName", "SelectedScheme=TRUE")
)
this will select the color from the table SchemaTableName where the field SelectedScheme is set to true.
Upvotes: 1
Reputation: 6336
Arguments of RGB function are numeric, not string, and there should be 3 of them:
RGB(136,207,39)
You are trying to pass one string argument.
You can use Split
function for extracting color values from string:
Me.boxheader.BackColor = RGB(Split(RGBcolor,",")(0),Split(RGBcolor,",")(1),Split(RGBcolor,",")(2))
Upvotes: 2