[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

WithEvents in Access 2000

Posted on 2001-09-12
15
Medium Priority
?
750 Views
Last Modified: 2012-06-27
I am TRYING to raise an event from a subform to the parent form.  Is this possible?  One would think it is.

In my "sub-form", I have an event declaration:

   Public Event ValueChanged(NewValue as Variant)

In the code of my sub-form, I raise this event:

   RaiseEvent ValueChanged("SomeNewValue")

I'm pretty sure I'm all set with that side of the problem.  Where I get a little mixed up is in the parent form, where the subform is placed.

I create an object variable of type Form_TestSubForm... my form is named TestSubForm, and the code module for it is named Form_TestSubForm, and this is my only choice in the dropdown list when I'm typing:

   Private Withevents TestForm As Form_TestSubForm

So, this seems to be okay, because the event list shows the ValueChanged event for my TestForm object.  Here's where I run into a problem.  What do I set TestForm equal to... i.e. I thought I had it when I said "Set TestForm = TestSubForm.Form", because it didn't give me an error... but it didn't work, either.

HELP!

Jay
0
Comment
Question by:taplin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +3
15 Comments
 
LVL 2

Expert Comment

by:hotbudare
ID: 6478239
I'd like you to be more specific as to what do you want to do
0
 
LVL 58
ID: 6479334
Jay,

  Your withevents is in a class module correct?  It won't work in a regular code module.

Jim.
0
 
LVL 2

Author Comment

by:taplin
ID: 6479896
JDettman:

I am not terribly familiar with Access programming.  I am more of a VB programmer.  I was under the impression that the form's code module would be a class module, similar to Visual Basic's form code being a class itself.  I don't get an error declaring or raising events from the code... wouldn't Access warn me?

hotbudare:

I am trying to create a subform that is unbound that hosts a calendar control.  Whenever the user changes the value of the calendar (changes dates), I want to raise an event from that form.  The reason I am choosing forms is because I am having serious window drawing issues with just the calendar control on the main form.  Suffice it to say I want it - need it - to function this way.

I am aware I do not have to raise events, but I would prefer to, as this is a much better form of communication than calling out to a procedure in the parent via referencing the parent.

Help!!!!

Thanks,
Jay
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58
ID: 6480760
Jay,

  Yes, form and report modules are class modules.  It just wasn't clear to me where you had you weithevents.

  I haven't played around with this, but try:

Private Withevents TestForm As Form

 instead of:

Private Withevents TestForm As Form_TestSubForm

and see if that works.  I'm not sure that it will. Subforms in Access are a bit strange.  It's like there not even there.  For example, screen.activeform will return the main form name if executed from code in a subform.  And a subform will not show in the forms collection either.

Let me know if that works.  If not, I'll try and set something up here.
Jim.
0
 
LVL 2

Expert Comment

by:hotbudare
ID: 6481418
You have to declare a calendar control variable type, not a form. The change event is associated to this control and NOT to the form itself. OTH, your code is creating and then "sinking" the event and, in your case you dont' need to, since this event does already exists.
Now, if I understood you right, I'm suposing you want your MAIN form to respond to a change made in the calendar control. Please correct me if I'm wrong.
I added a calendar control "CalControl" to form F1 and then added F1 to form F2 as CalSubForm. The coded in this commetn belongs to F2.
The problem is that this code fails in the first line of the Form_Load event procedure.
I've used this very same approach before but never on ActiveX controls.

I hope someone else could help. I'm done for today. It's late here and I'm very tired, but I'll give another shot tomorrow.

"EOC*************************
Option Compare Database
Option Explicit

Dim WithEvents Cal As MSACAL.Calendar

Private Sub Cal_AfterUpdate()

    Beep
    MsgBox "Calendar was changed!"
End Sub

Private Sub Form_Load()

    Set Cal = Me.CalSubForm.Form.Controls("CalControl")
    Cal.AfterUpdate = "[Event procedure]"
End Sub

Private Sub Form_Unload(Cancel As Integer)

    On Error Resume Next
    Set Cal = Nothing
End Sub
"EOC*************************

HTH/EQTA
T.S.U. Mario Osorio
Punto Fijo, Falcon, Venezuela

0
 
LVL 2

Author Comment

by:taplin
ID: 6482351
hotbudare:

I appreciate your advice... for the sake of my own pride, however, I do understand what you wrote... I had to put the calendar on a form because the calendar control itself wasn't drawing properly when overlaying subforms and such.  I'm trying to use it as a "dropdown" of a sort, similar to the way True DBInput controls work.

So, what I was doing was capturing the events from the control, and then hoping to use RaiseEvent to raise an even from within the calendar control event's itself.

Thank you for your help so far...
0
 
LVL 58
ID: 6482390
Still the same process though, no?  He's created a custom event at form level and creating a sink for the form, so he should get notification on the parent form.

Granted, going for an event on the control itself is more logical, but I don't understand why what he has now would not work.

Jay:
  Do you care if it's a form level event or one for the control?

Jim.
0
 
LVL 2

Author Comment

by:taplin
ID: 6482645
Okay... I'll try to explain this again... I guess I haven't been clear.

Initially, I placed the calendar control on my form, which has other controls on it, and also a subform.  Whenever a particular control got focus, I showed the calendar control just below it, so that the user could select the date graphically.  I would get the events from the calendar control to update the text box, and when the user double-clicked the calendar or placed focus on another control, the calendar would disappear.

This worked exactly right (as would be expected), except that the calendar control did not draw correctly if overlaying the subform that was on that form.  The border of the control would appear under the subform, whereas the control contents would appear above the subform.  I did not test to see if this just happens when interacting with subforms or not, but regardless, I needed this calendar control to "pop up" partially above the subform.

So, to rectify this situation, I decided to place the calendar control on its own form, then place that form onto the main form I was working with.  In a sense, this form with the calendar on it would be a sub-form and also behave as a control.

The only problem is, I can't seem to get any code-defined events from this form with the calendar.  I have other solutions, such as going to VB or VC++ and developing a control that would draw properly (or just place the calendar on top of a real window control, such as a picture box, and wrap it all up as a new activex control), but I would prefer to not resort to external solutions (external to Access, I mean).  This database could be accessed by many different computers, and I really don't want to deal with the issue of deploying ActiveX controls to each client machine.

Thanks for your help guys... trust me, I am pretty well skilled in VB and such... I understand the COM philosophies and understand how controls and forms interact... I really feel like I'm just missing some little thing about how Access handles code-defined events.

Really, all I want to know is: if I raise an event in form-code, and that form is placed onto another form as a sub-form, HOW DO I TRAP FOR THAT EVENT?

Thanks,
Jay
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 800 total points
ID: 6482894
Jay,

  Sorry I'm not more up on the withevents.  I've never really used it all that much.  But from what I have done with it, I can see nothing wrong with what you were trying to do, other then I would think that you would want to trap an event off the control directly.  I guess one point I should get clear is what you meant by:

"In the code of my sub-form, I raise this event:

  RaiseEvent ValueChanged("SomeNewValue")
"

 in your original question.  I was assuming that this code is in the AfterUpdate event of the control.

  I think also that you need to step back and look at the process.  While I'm not saying you can't do what your trying to do, there are simpler ways to do it. For example, from the calender control subform, you can call a method (sub procedure) in the parent just by doing:

  Parent.<method here>

  from any event procedure of the calendar control.  Creating a event sink gets you out of doing the above, but that's all it will do.

  Also keep in mind that Access is not VB and handles it forms entirely different.  For example, controls don't have handles, there are no control arrays, most ActiveX controls won't work because of a limited OLE container, etc.  I can appreciate that you are probably a very good programmer, but I'm just saying that you can't compare Access to C++ or VB.

 I can walk you through the steps for linking directly to the control if you wish, but I see nothing wrong with what you were doing at the form level.

Jim.

0
 
LVL 2

Author Comment

by:taplin
ID: 6482933
Jim,

Thanks for the information... yeah, I was beginning to gather that Access forms are handled completely different than VB forms (which, in turn, are handled completely different than Windows - C++ - forms).

The reason I prefer the method of raising events as compared to calling a method of the parent is that it forces the parent to be listening, rather than allowing the parent to be listening.  It is far more "reusable" to raise an event, rather than call a method directly.  Using your method, I would have to put an error handler in just in case the parent form doesn't have that particular procedure.  Along those lines, raising events works better because you can see from a simple dropdown what communication the control/form is using; that way, the programmer doesn't have to have knowledge, read documentation, or look at the control/form's code to identify what procedures are being called to communicate.

Anyway, to clarify my statement ""In the code of my sub-form, I raise this event:  RaiseEvent ValueChanged("SomeNewValue")", what I mean is that the calendar control fires an event (DateChanged, I believe).  In that event, I raise my event, ValueChanged.  This is just a method of passing the new value to whatever parent container is listening.

Anyway, I am beginning to think that I may have to resort to calling a procedure directly via the Parent.ProcedureName syntax, as much as I didn't want to.

If you have any thoughts, do let me know!  And again, thank you very much.

Jay
0
 
LVL 58
ID: 6482992
Jay,

 I'm hoping to have a little more free time this afternoo to play with this and re-visit it.  Which calendar control is it that you working with?

Jim.
0
 
LVL 2

Author Comment

by:taplin
ID: 6483069
I am using the MSCAL.OCX, the Calendar Control 8.0.

I appreciate your help.  Honestly, I haven't had any time to play with this either.  I spent about ten minutes with the WithEvents issue, and realizing that I didn't know enough about MS Access' way of doing things, I decided to post a question.  I think I'll be going back to it this afternoon also.

Thank you for your help!
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6836651
This question appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, you must tell the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below, include the question QID/link.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues.
http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20175079.html
http://www.experts-exchange.com/questions/Q.20180074.html
http://www.experts-exchange.com/questions/Q.20182134.html


PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:
 
Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange


P.S.  For year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6983065
for taplin

It's time to clean up this TA, so I will leave a recommendation in Community Support that this question is:
 - Answered by: JDettman  
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6997555
Per recommendation, force-accepted by
Netminder
CS Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question