Hello, all.
As winter is coming up and there's a lot of bright light during the day and then it gets dark quickly I thought about making a button on a form that lets the user switch between light and dark form control backgrounds.
I started with buttons based on code which I found online that seemed to make sense (I would later add more control types as necessary):
Private Sub CommandButton39_Click() Dim ctrl As Control Dim ct As String ct = "CommandButton" For Each ctrl In niTestIT.Controls If TypeName(ctrl) = ct Then ctrl.BackColor = RGB(64, 64, 64) End If Next ctrl End Sub
But I get a "Type mismatch" error. Any idea of what I am doing wrong?
Try this:
Private Sub CommandButton39_Click() Dim ctrl As Control, CB as commandbuttom Dim ct As String ct = "CommandButton" For Each ctrl In niTestIT.Controls If TypeName(ctrl) = ct Then set cb=ctrl cb.BackColor = RGB(64, 64, 64) End If Next ctrl End Sub
'Control' may have different types, you need to bring this object in the correct controltype before
Hey, thanks for your input!
Unfortunately I am getting the same error as stated previously. This is with CorelDRAW 2018, btw.
If I use the color setting directly, say: "CommandButton1.BackColor = RGB(255, 0, 0)" then it works, but using the loop it does not...
If nothing else I can just change the colors of all the elements by hand, they shouldn't really change after I'm done designing the form. But a universal approach would be nicer of course.
At which line you get your error?
I modified your code without testing
Now I saw a small typo: ... , CB as CommandButton
Maybe this will fix it
Alright, I found the source of the error!
As I was typing up Cont... The autocomplete showed Control twice. So once I changed that to MSForms.Control it works just fine.
So basically that was the main error here, something I should remember for the future.