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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[b] Passing a value to a form activated from an ocx [/b] 1

Status
Not open for further replies.

jlitondo

MIS
Jun 27, 2000
175
US
Here is the ideal scenario - When a command button on an Active X control that is embeded in a datarepeater is clicked, a popup form loads and displays detailed information based on the ID of the current record on the repeater control.

I am passing the Id of the current record to a public property of the main form whenever the open button in the ocx is clicked. This Id is obtained from the CurrentRecordChanged() event of the repeater control.

However, if the popup form is opened from the button on the ocx, it does not retrieve the value passed and hence no records are displayed on it.

On the other hand, if the popup form is opened from a command button on the main form, it loads up fine and displays all the records like its supposed to.

So what's the difference besides where the form is loaded from? Is there any other way of tackling this issue?



 
The form you open is part of a form array? I mean do you create the form in runtime?
Here you got an example on creating form in runtima and you can be in control of every object in the form.
Form1 is your app
Form2 is the popup form

In a module:
Global scriptform() As Form2, formnumber

To create the form you put this code under the command button sub:

formnumber = formnumber + 1
ReDim Preserve scriptform(0 To formnumber) As Form2
Set scriptform(formnumber) = New Form2
scriptform(formnumber).Show

Now suppose you got a Label called Label1 in the form2, since you created scriptform(x) from Form2 a Label1 will be placed on scriptform(x) too so you can access label1 like:
scriptform(1).label1.caption = "My Text"
Your label1 in the form you created will display MY TEXT.
Hope it helps (excuse my english)
 
Hi alehawk,

Never mind the English, its not my first language either :) Thanks for the input though.

I tried your implementation above and I have a few questions for you. After I assign "My Text" to label1 it displays fine the first time but once I close the form and click on the button again, the text is not assigned. The button is on an ocx in a datarepeater so I don't whether the ocx does not recreate the form. I'll check for this.

Wouldn't storing the form objects in a dynamic array be a memory hog if the form is created and loaded several times in one session?



 
What whoy have to do is to redim the scriptform whenever you add a new form or you remove the form, becaose when you remove the form and you redim scriptform(formnumber) to scriptform(formnumber-1) you recover the amount of ram that the closed form used.
I use this kind of creating form in a custom sticky notes app where I create sticky notes and I also set alarm values to each one to alert me of some note at desired time. It really works :)
 
Thanks alehawk, I did that and it works.

But now there is another problem. Since I am assigning this value from a main form which typically has several records, I am only able to pick up the value of the 1st record in the main form. How would I get the active record id from the main form?

It seems to me that since the ocx resides in a separate project from all the other forms, any form it loads will be loaded within its "work space" even if that form resides in a different project. Therefore the ocx is not able to pick out any data from the main form which is running in a separate "work space" (if that is the right phrase to use).

Do you have any idea on how to make the ocx aware of data on the main form so that it can pass this on to the popup form? The ocx is embedded in a datarepeater which sits on the main form.

I tried picking this value from the popup and it too is not able to see it. I also tried passing the value of the main form's property to a global variable so that the ocx can see it but to no avail.

 
When you say that the ocx is in a separate project you mean that you got 2 apps working together?
If its not and since a global variable wont let you get the record ID (dont know why, I guess some ocx stuff), if you want to get the ID you can put a hidden label on your main form or a listbox and set the ID, open the popupform and get the ID from the popupform like mainform.label1.caption or the same with the listbox...
 
Yes, I have a main project and an ocx project.

I placed a text box on the main form and then everytime the active record changed on the datarepeater, i assigned its Id to this text box.

I placed another button on the main form to open the same form that is being opened from the ocx and I noticed something interesting. If I open the popup from the button on the main form, I can assign any value to it from any object of the main form. But if I load it from the button on the ocx, the popup is not able to pick up and values from the main form. Any ideas?

 
I figured it out!!!

Since the controls of the ocx are able to receive data while on the datarepeater, i added hidden unbound text boxes on the ocx and added a Let public property(no need for a property Get since we are not writting back to the database) for each. I also included the propertychanged for this text boxes.

When the load form button on the ocx is clicked, I retreive the current record Ids' from the repeater control and assign them to these text boxes. I then grab the text boxs' text values and assign them to global variables in a module declared within the ocx. These variables can then be referenced by the popup form's load event so that they can be used in the stored procedures that the form calls for data.

This way I'm able to pass data between my ocx and a form that resides in a separate project. If anyone else has a different method of accomplishing this, please post here. It would be interesting to see.

Thanks for your input though, alehawk. I did learn something new from you.

 
I have another one :) Do you know of a way to make the datarepeater load with an empty row at the end of a row list? For example, if you open a continuous form in MS Access with a list of rows, a blank row is made available for quick data entry. Thanks.

 
You mean using datagrid or something? I'd never use datagrids... sorry :(
 
no, just using a datarepeater control that has an ocx embedded in it. But it would look like a datagrid with a blank last row for adding a new record.

 
yet another one for you alehawk. I have a combo box with two fields, ItemID and ItemDescription. How would I display ItemDescription on the combo box but only save the ItemId back to the database. So far I am only able to display and save one of them.

 
if the ItemID is of type "integer" then set the itemData property of the combobox to the ItemID value.

As for displaying both there are several options.

Tab Separated
listview control
...

Search more on this forum to find out how.

Also, this would be the time to start another thread as the question is beginning to stray from the original post.

Matt
 
You are right MattSTech, the question deviates from the original post. I did a search in other forums for the combo question and found a few possible solutions which I am currently playing with.

 
For the combo I should use an array so that itemdescription = arritemid(combo1.listindex) so you can store the arritemid whick value is the itemdescription's itemid. (Hope you undestand what I'm tryiing to say :) )
Also You can do as Mattstech told, using a listview control...
Cya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top