Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making ActiveX control - just a texbox 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone get me off the ground. I want an activeX control consisting of just a text box that can be accessed/filled by the application it gets put on. Many thanks
 
You'll want to check out this link
You might also do a search at planet source code for examples.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thanks, but I find the pages on the site have either gone/moved or whatever, as they permanently display a server error message. I have found a large number of links to MS end up as error 404/Page not found. I will give Planet source code a try again. Thanks.
 
The links work for me, the exact article can be found in vb help and it refers to a sample that on my computer can be found here:
C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98\CtlPlus

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Many thanks, I have looked at planet sourcecode, registered peoples ocx to try examples, but they all refer to entering data into the activex control itself. I am trying to put text into a texbox Text1 from the form the activex is on. Is it possible to put data from the form into the activex textbox, label or whatever. Not worried about events on the activex, its just a display object. Many thanks
 
ZOR,

You can add properties using the Let and Get subs, inside the control. "Let", lets you assign a property, and "Get" fetches the property.

That means, MyCtl.Text="Text" calls the "Let", and if it is missing, you cant set that property in the form or, the property becomes "Read Only".

and when querying MyCtl.Text, the "Get" fetches you the value that the property holds currently. If there is no "Get" defined, then that property will be "WriteOnly"

You will better understand if you step through your Active X code, after placing in a form.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Thanks vbSun, I will play with that and use debuuging to see whats what. Basically I am trying to create an Axtivex control to put on an Access Form. As MSAccess does not seem to do texbox array's, I'm trying to do a hybrid. All it is is a display panel of some 12 Textboxes, or it could be labels, that Access Fills up. Thanks again. Have a star for starting me moving. Have a good weekend.
 
I never got there. Tried and tried but still could not get external input to activex listbox. I kept getting the dialogue "Needs an object"
So, if anyone can get the chance to show me code how a single textbox or label created as an activex control can be filled by a button OUTSIDE of the control, I would ve very greatful. I am wanting to use the control on MS Access. Best regards.
 
Erm...have you tried using tVB's ActiveX Control Interface Wizard (it is one of the options that you get if you select 'Add User Control" from the Project menu). It will lead you by the hand for each step and has a help button on every page of the wizard. It is not the most flexible tool, but it should illustrate the basic how-to's for you (with the bonus of providing working, if inelegant, code at the end).
 
Zor,

Thanks for the star! Let me try and demonstrate adding a simple property and resizing capability for a textbox based usercontrol. I have used VBs' ActiveX Control Interface Wizard to build this, and I think it is the same as what strongm was suggesting.

Here we go..

1. New Project.
2. Form1 is created by default.
3. Right Click on the Project Explorer, and select Add->User Control.
4. Put a textbox on the UserControl.
5. Open the codewindow for the usercontrol, and paste the following code.

Code:
Option Explicit

Public Property Let Text(ByVal New_Text As String)

    Text1.Text() = New_Text
    PropertyChanged "Text"

End Property

'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Text1,Text1,-1,Text
Public Property Get Text() As String

    Text = Text1.Text

End Property

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    Text1.Text = PropBag.ReadProperty("Text", "Text1")

End Sub

Private Sub UserControl_Resize()

    Text1.Move 0, 0, Width, Height

End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    Call PropBag.WriteProperty("Text", Text1.Text, "Text1")

End Sub
6. Now open the Form (Form1), and place an instance of your control in it.

7. Along with that, place two Command Buttons (Command1 and Command2).

8. Paste the following Code in to the Form's Code window.


Code:
Option Explicit

Private Sub Command1_Click()

    UserControl11.Text = "Custom Text"

End Sub

Private Sub Command2_Click()

    MsgBox UserControl11.Text

End Sub

9. Run the project and click on the buttons.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Many thanks vbsun, and strongm, sorry for delay getting back, worked away for the week. I followed things through, and got the example working in vb. I created the control manually following your code, by selecting a new project/user control. However despite then making it an .ocx, registering it, I found my tasks reach a dead end again trying to apply it on an Access form. Access gives no indication as to what activex's will work other than its dropdown list of those that will work. (so it states), however its untrue as the flexgrid etc cannot be used etc. There seems to be a brick wall between applications, no commonality between controls etc, almost as a deliberate ploy to make things not work or they were all developed by MS developers at each end of the planet. Third party grids for use in Access are so expensive, probably like always doing more than a user actually wants. All I am wanting is to have a texbox array or label array for use in an access form. Only need to display data, and respond to click event on each label/textbox. Has anyone ever done it?, can it be done?. MS seems to have removed a lot of information in its search database, even VB6 info on the net is fast being replaced by VB Net. Appreciate any feedback/suggestions. Many thanks again
 
Er... but you can fairly simply build a close approximation of a Flexgrid in Access (for example, use the Form Wizard and select Datasheet for the layout); the original MS Grid control (and other 3rd party grid controls) was intially produced in response to VB users wanting something like Access' Datasheet layout in VB
 
Thanks for the suggestion, however the datasheet is so limited compared to the flexgrid. Unless I'm mistaken, I cannot merge cells, show colours in cells apart from label backgrounds etc. I am really trying to find out once and for all, can an activex label or text array be put on a standard Access form and be talked to externally on the form. I have tried the other forums, Access,Activex etc but nobody comes back on it. If it's not possible then okay I will know and stop wasting time on it. I don't have the developers version of Access, soI can't work backwards on it. Appreciate all your help. Regards
 
John, You Could always try using SAX?
(Joke) ;-)

jgjge3.gif
[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
>can an activex label or text array be put on a standard Access form and be talked to externally on the form

Yes, they can. As we've said. And yes, the code you've been given here does the trick, as does the code that is generated by the wizard that I suggested you look at. They really do. Honest.

 
Well I followed VBSun's example, ran it in VB, and yes it works. It produces a visual basic control .CTL . How do I get it into Access from here on?. The only option I see at the vb stage is to create a Project1.exe. I cannot see a way to create an .ocx, which I think Access wants although I might be wrong. I tried making part one, ie the user control into an .ocx thinking part two, ie the pushbuttons could be put on an Access form and it might talk, but got nowhere. Will carry on trying to see whats what, but soon will have to throw it out as too much time being spent against a brick wall. Thanks Jag, managed to grit my teeth with the joke, I wish Scotty would beam me up!
 
In the VB IDE choose the File Menu (while working on your control) and you will have the option Make Control1.OCX

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thats it, I'm happy, it's in the dustbin. Went through all the possibilities, save UserControl1 as .... Save project as ...... Make Project ..... Eventually got an .ocx. Tried registering it, failed. Went into Access, Tools/Activex controls, no sign of it, no browsing. Looked at insert Activex object, no sign of it. Looked at Toolbox/further tools, no sign of it. Found plenty of previos attemts - Project1.Usercontrol1 - Not OLE registered - Then whoooosh, cleared everything off, smiled, thought there are better things in life on a weekend. Thanks anyway, sent out more stars, its switchoff time before they take me away in a big van.
 
Ah... sounds like you've simply been adding a usercontrol to a "Standard Exe" project. You need to start with an "ActiveX Control" project if you expect it to compile to a proper registerable OCX
 
YoU MeaN To Say I hAvE CraCked uP BecAUse I StARteD WiTH tHe WrOnG PrOjEcT? I WiLl TaKe AnoTHer PilL AnD TRy AgAin.
AggghhhHHHH. ThAnK YOu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top