473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is it possible to change an event procedure from VBA?

gnawoncents
214 100+
I have a dynamic report (created from VBA coding) and I want to set the OnClose event procedure to make another form visible when the report closes. I cannot access the events in the report itself since it doesn't exist until the user presses a button.

I have tried several variations with negative results:

Expand|Select|Wrap|Line Numbers
  1. Set Reports(rpt.Name).OnClose = "Forms!FRMDynamicReport.Visible = True"
  2.  
(Where rpt.Name is the name of the newly created report)

AND

Expand|Select|Wrap|Line Numbers
  1. Reports(rpt.Name).OnClose = "Forms!FRMDynamicReport.Visible = True"
  2.  
OR

Expand|Select|Wrap|Line Numbers
  1. Reports(rpt.Name).OnClose = Forms!FRMDynamicReport.Visible = True
  2.  
ETC.

My primary question is this: Is what I'm trying to do possible? If so, how? If not, is there another way to go about accomplishing the same thing?

Thanks for your help!
Sep 28 '10 #1

✓ answered by MMcCarthy

OK in the code where the report is created dynamically you will have a report object. For this purpose lets assume that object is called rpt.

As part of your code you need to add the on close event as part of that report creation as follows.

Expand|Select|Wrap|Line Numbers
  1. Dim mdl As Module
  2. Dim lngReturn As Long
  3. Dim strCode As String
  4.  
  5.     strCode = vbCrLf & "   Forms!FRMDynamicReport.Visible = True"
  6.  
  7.     Set rpt = Reports("rpt.Name")
  8.     Set mdl = rpt.Module
  9.     ' Add event procedure.
  10.     lngReturn = mdl.CreateEventProc("Close", "Report")
  11.     ' Insert text into body of procedure.
  12.     mdl.InsertLines lngReturn + 1, strCode

8 5673
Oralloy
988 Expert 512MB
Have you tried creating a support module which holds a state variable that the report can access?

Your report will copy the state value as part of the "Report_Open()" method.

Then the "Report_Close()" method acts, based on the saved state value.

Does that make sense?
Sep 28 '10 #2
slenish
283 100+
I found another post about dynamic reports here in bytes that might help you.

http://bytes.com/topic/access/insigh...port-using-vba
Sep 29 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
Your problem is that since you can't access the events of the report how to you trigger the on close event. It's an interesting problem :)

Let me see what I can find out and I'll get back to you.
Sep 29 '10 #4
gnawoncents
214 100+
Have you tried creating a support module which holds a state variable that the report can access?

Your report will copy the state value as part of the "Report_Open()" method.

Then the "Report_Close()" method acts, based on the saved state value.

Does that make sense?
Oralloy,

I'm not entirely sure what you mean by "state variable." If it is something the report should access, then unless I am mistaken I am still stuck with the problem of how to tell the as of yet nonexistent report that when it is created to look at the state variable. I might just be missing your point though... please clarify. Thank you!

----

Slenish,

Thanks for the response, that's actually the main resource I used to create the dynamic report coding.

----

MMcCarthy,

Yes, that's exactly my problem. I toyed with the idea of a timed event, but am loathe to go that route. Please let me know if you come up with anything. Thanks!
Sep 29 '10 #5
MMcCarthy
14,534 Expert Mod 8TB
OK in the code where the report is created dynamically you will have a report object. For this purpose lets assume that object is called rpt.

As part of your code you need to add the on close event as part of that report creation as follows.

Expand|Select|Wrap|Line Numbers
  1. Dim mdl As Module
  2. Dim lngReturn As Long
  3. Dim strCode As String
  4.  
  5.     strCode = vbCrLf & "   Forms!FRMDynamicReport.Visible = True"
  6.  
  7.     Set rpt = Reports("rpt.Name")
  8.     Set mdl = rpt.Module
  9.     ' Add event procedure.
  10.     lngReturn = mdl.CreateEventProc("Close", "Report")
  11.     ' Insert text into body of procedure.
  12.     mdl.InsertLines lngReturn + 1, strCode
Sep 29 '10 #6
Oralloy
988 Expert 512MB
gnawoncents,

It's interesting that slenish's post points to one of Mary's posts. They're both really good at this sort of thing.

I was thinking that you had an existing report that you were modifying on the fly and adding code to. Thus, I must bow out of this, I think.
Sep 29 '10 #7
gnawoncents
214 100+
Thank you all for your help.

MMcCarthy,

I stripped the quotes from "rpt.name", and once I realized I should add the code before the open report line, it worked like a charm. Thank you again!
Sep 29 '10 #8
MMcCarthy
14,534 Expert Mod 8TB
LOL, sorry about the quotes. I had a report name in when testing it and I forgot when I copied the rpt.name in.
Sep 29 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marksmanaz | last post by:
I have a form named with a subform named based on a query with two controls called (text) and (Yes/No Checkbox). When the checkbox value is yes another query filters for Available Counselors...
3
by: Jason | last post by:
I have an ASP.NET application in which I would like to call my button click event (imgSubmitSearch_Click) on the page load if certain criteria are met. Is this possible? What is the correct...
10
by: jerry.ranch | last post by:
I have a series of comboboxes on a form that are used to display forms in DS view (theres a qry behind it all). This is working well for me. Some people like to see the data in DS view, some in...
1
by: Robert | last post by:
Every thing worked fine until all of a sudden, I get the following error whenever I try to do anything on one of my forms that calls an Event Procedure. I get the error as soon as the form opens...
6
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If...
1
by: Kuldeep | last post by:
Hello All, Visual Studio 2005 ASP.NET 2.0 C#.NET 2.0 I have an application which has a Button click event procedure as given below. protected void btn_Click(object sender, EventArgs e)
0
by: =?Utf-8?B?SiBTdHJlZ2Vy?= | last post by:
I have a procedure to increase/decrease the size of the columns in a datagrid proportional to their original size. I want to capture the event if a user manually resizes a column, so I can reset my...
1
by: AMD_GAMER | last post by:
Hi, I am trying to print address labels. I have a form which asks for the user to input the first name, middle initial, and last name. On the button click to print the label, I have an event...
3
by: grinder332518 | last post by:
My Form accesses a Query as follows : SELECT tblA.A, tblB.B, tblB.C FROM tblA LEFT JOIN tblB ON tblA.A = tblB.A UNION SELECT tblB.A, tblB.B, tblB.C FROM tblB LEFT JOIN TblA ON ...
2
by: Bre035 | last post by:
I am attempting to require certain field be populated with data, save the record, and open a new form in one Event procedure when a Comand Button is selected on Form. Unfortunately, this is erroring...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.