473,326 Members | 2,147 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,326 software developers and data experts.

How to Write Onclick Event for dynamically created buttons using VBA in MS Access

7
I am stuck with a Event Procedure Issue. I have created one Dynamic report in MS access using VBA. For the same I have created some dynamic controls like lables, Textbox, buttons, etc. I am able to create report successfully. The only issue is that I don't know how to create "Onclick" Event procedure for Dynamically created button. Every Time I click on that button it gives me an errors which says " No such Event found" kind off.
Here is My Code...

Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_createReport()
  2.  
  3. Dim btnNew As Access.CommandButton
  4. Dim rpt As Report ' hold report object
  5.  
  6. cmdSelect = "select * from xyz;"
  7. Set rpt = CreateReport
  8.  
  9. ' set properties of the Report
  10. With rpt
  11. .Width = 12500
  12. .RecordSource = cmdSelect
  13. .Caption = title
  14. End With
  15.  
  16.  
  17.  
  18. Set btnNew = CreateReportControl(rpt.Name, acCommandButton, acPageHeader, , , 7000, 50, 1500, 400)
  19. btnNew.Caption = "Back"
  20. btnNew.Name = "btnNew" 
  21.  
  22. ' btnNew.OnClick = "[btn_Click]"
  23. 'lblNew.FontUnderline = True
  24. lblNew.SizeToFit
  25.  
  26. End Sub
  27.  
  28. Private Sub btnNew_Click()
  29. DoCmd.OpenForm Form1, acNormal, , , , acWindowNormal
  30. MsgBox "Hello"
  31. End Sub
Apr 18 '13 #1
2 15790
ADezii
8,834 Expert 8TB
I missed the Report part because I am running out the door, but here is how you can create an Event Procedure (Click()) for a Control (Command Button) named cmdDemo on the Current Form:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. Dim mdl As Module
  3. Dim frm As Form
  4.  
  5. Set ctl = Me![cmdDemo]      'Set a Reference to the Command Button
  6. Set frm = Me                'Set a reference to the Form
  7. Set mdl = Me.Module         'Set a Reference to the Form's Code Module
  8.  
  9. 'Create a Click() Event Procedure for the Command Button cmdDemo
  10. lngReturn = mdl.CreateEventProc("Click", ctl.Name)
  11.  
  12. 'Insert a single Line of Code in the Event Procedure
  13. mdl.InsertLines lngReturn + 1, "Msgbox ""Create Procedure Demo"""
Apr 19 '13 #2
Maya16
7
Thnx For The Reply....
Apr 22 '13 #3

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

Similar topics

3
by: Jim Mitchell | last post by:
I have some code behind that generates 10 imagebutton controls.... I can not seem to figure out how to trap the onclick event for each image and determine which image was clicked. Can someone...
10
by: drawde83 | last post by:
Hi, I'm mocking up an interface in javascript for an HCI assignment. I want to be able to make the default onclick event for the buttons on my page to display an alert since the buttons won't work...
1
by: Hrvoje Vrbanc | last post by:
Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button = New Button() celija25.Controls.Add(btObnovi) ...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
2
by: Sandeep | last post by:
Hi I want to write onclick event on a button(a web control) ,also i want to call a client side function on the click event how to write that how to differentiate between these two events ...
1
by: tshad | last post by:
Is there a way to change the onClick event of a LinkButton? At the moment, I am using 2 buttons that I toggle the visibility on and off. I would like to use just one button, if possible and just...
2
by: DataSmash | last post by:
Hello, I've created a simple form with 2 radio boxes, 2 text boxes and a button. When I click the button, I'd like to write each "choice" to a text file. I can't figure out how to "link" the...
6
by: Totto | last post by:
Hi, Anyone know the best solution to dynamically add buttons to a asp 2.0 page using data from Sql server? Are there any contols suitable for this or is it best to iterate the dataset and...
6
by: Nathan Sokalski | last post by:
I have a DataList which contains several LinkButtons, which are used to select a category in my application. I want the currently selected category to use a different CSS class. Here is an example...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.