473,791 Members | 3,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating Form Using Form Events Rather Than Control Events

3 New Member
I have an Access 2003 form with 58 checkboxes. Each checkbox has 2 corresponding combo boxes, which I would like to keep hidden until their box has been checked. The naming is consistent, with the checkboxes named "chkName" and the combo boxes named "cboName_Rating " and "cboName_Durati on".

Since there are so many checkboxes, I want to eliminate having to put a function call in the AfterUpdate event of each one. Here is what I am trying to use on the Form level, but cannot find the appropriate event to attach it to, if there is one:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.   Dim nm As String
  4.   Dim nmLong As String
  5.  
  6.   If Me.ActiveControl.ControlType = acCheckBox Then
  7.  
  8.     nm = Mid(Me.ActiveControl.Name, 4)
  9.  
  10.     If Me.ActiveControl = -1 Then
  11.       nmLong = "cbo" & nm & "_Rating"
  12.       Me(nmLong).Visible = True
  13.       nmLong = "cbo" & nm & "_Duration"
  14.       Me(nmLong).Visible = True
  15.     Else
  16.       nmLong = "cbo" & nm & "_Rating"
  17.       Me(nmLong).Visible = False
  18.       nmLong = "cbo" & nm & "_Duration"
  19.       Me(nmLong).Visible = False
  20.     End If
  21.  
  22.   End If
  23.  
  24. End Sub
I know the code is good because it will work on the last changed checkbox if the form is saved, but I can't get it working in real-time as each box is checked.

I am probably just creating more work in being lazy, but it seems like a good theory to me. Thanks in advance for any help!

Tony Leonard
Mar 10 '08 #1
7 2317
Lenny5160
3 New Member
Thanks, but those all look like they require an additional button to be pressed to run the code. I am looking for a Form event that would be triggered whenever any data on the form is changed. I might just need to bite the bullet and call my code in the AfterUpdate event on each of the 58 checkboxes.
Mar 10 '08 #3
NeoPa
32,579 Recognized Expert Moderator MVP
...
I am probably just creating more work in being lazy, but it seems like a good theory to me. Thanks in advance for any help!

Tony Leonard
Tony, since when was lazy a bad thing in a programmer?
I will try to look at this for you and see what I can come up with.
Mar 11 '08 #4
NeoPa
32,579 Recognized Expert Moderator MVP
Tony,

I'm surprised you managed to get this code to trigger at all. Mine didn't.
The only way i would imagine it would, would be if the form fields were bound to a record source.

That's possibly the case. Is it?
Mar 11 '08 #5
NeoPa
32,579 Recognized Expert Moderator MVP
...
I know the code is good because it will work on the last changed checkbox if the form is saved, but I can't get it working in real-time as each box is checked.
...
I just reread the original post and now realise the question is sort of in two parts.
  1. Why doesn't my code work for each update?
  2. Is there a Form event that will trigger when a (bound) CheckBox value is changed?
Answers
  1. The Form_BeforeUpda te event procedure is triggered only when a save occurrs. This is often simply when you move from one record to another. It doesn't trigger for each change on the form.
  2. No. I'm afraid there's not. Even the Form's Click event only triggers on the form if there is no control effected.

What to do?

I would consider writing a sub to do the main part for you, then create control_AfterUp date event procedures that simply call this sub.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowHide()
  2.   Dim strName As String
  3.  
  4.   With Me
  5.     If .ActiveControl.ControlType <> acCheckBox Then Exit Sub
  6.  
  7.     strName = "cbo" & Mid(.ActiveControl.Name, 4)
  8.     .Controls(strName & "_Rating").Visible = .ActiveControl
  9.     .Controls(strName & "_Duration").Visible = .ActiveControl
  10.   End With
  11. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkName1_AfterUpdate()
  2.   Call ShowHide()
  3. End Sub
  4.  
  5. Private Sub chkName2_AfterUpdate()
  6.   Call ShowHide()
  7. End Sub
  8.  
  9. Private Sub chkNamen_AfterUpdate()
  10.   Call ShowHide()
  11. End Sub
It's not as tidy as you would have liked, but it's better than full kit and caboodle option.
Mar 12 '08 #6
Lenny5160
3 New Member
Yes, I was planning to write a standalone sub or function that would be called by each AfterUpdate event if that is how it needed to be. Your way is a little neater than mine though. Thanks!

I pasted the BeforeUpdate sub because that is the last place I tried the code. At the same time, I was also moving a "DoCmd.Save " among the Click, Dirty, and MouseDown events hoping they would in turn trigger the BeforeUpdate event. No such luck.

I really appreciate the effort!
Mar 12 '08 #7
NeoPa
32,579 Recognized Expert Moderator MVP
A pleasure Tony.

I needed to brush up on some of those issues anyway so it was interesting :)
Mar 12 '08 #8

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

Similar topics

0
1873
by: jphelan | last post by:
I have a subform that works fine until you import it into a new database when it crashes if you try to open it in either disign or form view. The form, "Attendees_Subform" in my application was pattern after the same form used in the MS template, "Event Management.mdb" application that is downloaded from the MS Template Gallery on their website. I narrowed down the problem to the Control Source in the, "Attendees_Subform using the...
8
12107
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
4
1535
by: RL Stevenson | last post by:
Often I want to change the Enable or Visibility on a control when some other control on the form changes. Or maybe I need to make a change to the DataSource on a combo box when the user makes a selection elsewhere on the form. In Visual FoxPro, you would call Refresh on the form causing Refresh to be called on all the controls on the form, causing the Refresh event code to be called and allowing the controls to update themselves to the...
7
2578
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
5
12532
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
4
1490
by: Simon Tamman {Uchiha Jax} | last post by:
Scenario: Two System.Windows.Forms: Form1 and Form2. Form1 is displayed, Form2 is hidden. At this juncture, is it possible to take the graphics from Form2 and output that to Form1's display and take all of the mouse and key events from Form1 and pass those on to Form2, thus changing the graphical output on Form2 and then pasting those graphical changes back to Form1? Is this some kind of P/Invoke job?
9
4669
by: Kevin Blount | last post by:
Here's the code I tried, and found it failed... <form runat="server" method="post" name="CreditCardForm" id="CreditCardForm"> <% foreach (object item in Request.Form) { if (item.ToString().IndexOf("__") != 0) { //Response.Write(item + " = " + Request.Form +
8
36139
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query button on it. If the query returns multiple results, a new window is opened with a grid containing the results. When the user double clicks on the desired row in the grid, I want the first form to populate with the correct data. I don't know how...
4
3199
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I developed a Composite Control with Visual C# (Rocker Button). The button detects MouseUp events inside the control. However I would like these MouseUp events to be transferred to the parent form of this control so I can update the form with the new information. The messages are trapped inside the control but are not seen by the parent form.
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.