VB Control for Access continous forms

bog2731
bog2731 used Ask the Experts™
on
How do I display data from the Access ControlSource
in my VB Custom Control?


I've made VB ActiveX Controls (.ocx), and put them
on my Access forms before.

Now, I want to be able to set the control's
ControlSource property, so my control can display
'bound' data (like when you type "=FirstName" in a
textbox on a form).

The reason is to change the background color of
records in a continous form. Ex: in a list of
transactions, make any negative transactions have a
red background and any positive transactions have a
black background.

So I make a new "ActiveX Control" vb project, throw a
textbox in it, and add this code:

Private Sub UserControl_OLESetData
 (Data As DataObject, DataFormat As Integer)
  MsgBox "set data"
End Sub

Then, I added the control to my Access form like normal,
and realized it didn't have a ControlSource property.

One I get the ControlSource, I know how to use built-in
functions in Access to feed my control a RGB number.

I also know how to respond to the RGB number- how to
color the bg.

This is my first question- tell me if I'm doing it wrong
:-)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
If your using Access 2K2, you could probably succeed by using the form's Conditional Formatting.  Right-click on the field that represents the negative/positive transaction and select Conditional Formatting.  You can then make the setting to change the font color according to your criteria.

Author

Commented:
rvazquez, I may have oversimplified here.

Although your suggestion makes sense for the
example I gave, I actually do need to change
the background color- not just show that a
number is negative.

Commented:
how about covering your whole form with a text box and setting its control source as the transaction field?  Send it to Back and apply Conditional Formatting to it.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
As you may already know, there's a four-criteria limitation to Conditional Formatting.  But since you're only dealing with positive/negative, you should be okay.

Just make sure you set the textbox's background and font to the same color.

This 'cheat' works nice in continuous forms.

Author

Commented:
OK, let's go back to the question...

How do I display data from the Access ControlSource
in my VB Custom Control?

Commented:
i take it that my suggestion doesn't accomplish your desired end result?

Author

Commented:
Not really, no...

Sorry.

Author

Commented:
Not really, no...

Sorry.

Commented:
how does it fall short?  from what I understand, you'd like to change the background color of each record according to positive/negative transactions.  

Author

Commented:
Well, because later I'm going to do other stuff besides set the background color.

Also, because I want to learn how to do it with a VB Custom Control.

Commented:

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
Per recommendation, points refunded and question closed.

Netminder
EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial