INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Open form in .exe using button in .ocx

Open form in .exe using button in .ocx

(OP)
Hi there,

I've made a custom  .ocx control consisting of a command button and three text boxes:

[btnGo] [txtAccountNum] [txtName] [txtContact]

In my .exe, I have created a data repeater, using the .ocx. It looks something like this:

[btnGo] [txtAccountNum] [txtName] [txtContact] (record 1)
[btnGo] [txtAccountNum] [txtName] [txtContact] (record 2)
[btnGo] [txtAccountNum] [txtName] [txtContact] (record 3)

...a new line for each record--so far, so good.

How do I code [btnGo_Click] (which is part of the .ocx), to open a form in the .exe (in which the .ocx is used) AND point that form to the corresponding record?

Thanks in advance!

RE: Open form in .exe using button in .ocx

I don't believe that a user control (i.e. An OCX) knows anything about the app in which it is used so you probably can't do this completely within the OCX.

You can however raise events from within the OCX and process them within your app like this

CODE

In the OCX
Public Event OpenForm(RecordID As String)

Sub btnGo_Click()
Raise Event OpenForm ("Record1")
End Sub

In your EXE
Sub OCXName_OpenForm(RecordID As String)
Set frm = New FormToOpen
frm.RecordID = RecordID
frm.Open
End Sub

And finally in the form that is being opened
Private mvarRecordID As String

Public Property Set RecordID(vData As String)
    Set mvarRecordID = vData
End Property

Here "OCXName" is the name by which the OCX is known in your EXE.

RE: Open form in .exe using button in .ocx

(OP)
Thank you, Golom, for your response.  This sounds like something I can work with.  I'll let you know my outcome.  

RE: Open form in .exe using button in .ocx

(OP)
This is what I did:

I added a text box, [txtidxClients], to ClientsCtl.ocx.
I set its DataField property to idxClients.
I added this code to ClientsCtl.ocx:

CODE

Public Event OpenForm(RecordID As String)

Public Property Get ClientID() As String
    ClientID = txtidxClients.Text
End Property

Public Property Let ClientID(ByVal newClientID As String)
    txtidxClients.Text = newClientID
End Property

Private Sub ClientID_Change()
    PropertyChanged "ClientID"
End Sub

Public Sub btnGo_Click()
    RaiseEvent OpenForm("ClientID")
End Sub
In Tools>Procedure Attributes, I selected Name: ClientID, and in >Advanced I checked "Property is data bound," "This property binds to DataField," "Show in DataBindings collection at design time" amd "Update immediate."

Then, in the EXE, in frmClients (which contains ClientsCtl.ocx), I put the following code:

CODE

Sub ClientsCtl_OpenForm(RecordID As String)
    Set frm = New frmClient 'the name of the form to open
    frm.txtidxClients = RecordID
    frm.Open
End Sub
Then, in frmClient (which I want to open), I put:

CODE

Private mvarRecordID As String

Public Property Set RecordID(vData As String)
    Set mvarRecordID = vData
End Property

Upon compilation of the EXE, I get the following Compile Error:

"Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter"

I don't know enough to see where I've gone wrong!

 

RE: Open form in .exe using button in .ocx

The problem is probably here (and also probably my fault).

CODE

Public Property Set RecordID(vData As String)
    Set mvarRecordID = vData
End Property

It should be

CODE

Public Property Let RecordID(vData As String)
    mvarRecordID = vData
End Property

Set is used to assign values to objects. Just do the assignment without the SET keyword and use "Property Let" rather than "Property Set".

"Let" assigns a value to a variable.

I also note that you are returning the fixed string "ClientID" in the raise event. You probably want to return txtidxClients.Text which is the current ID of the client that you want to display.

RE: Open form in .exe using button in .ocx

(OP)
Thank you, Golom, for your assistance.  You are really helping me to sneak up on it. I've made the changes you posted, and now the EXE gives a different Compile Error: Object required.  It happens on:

CODE

mvarRecordID = vData
Thanks again for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close