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: - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
-
Dim nm As String
-
Dim nmLong As String
-
-
If Me.ActiveControl.ControlType = acCheckBox Then
-
-
nm = Mid(Me.ActiveControl.Name, 4)
-
-
If Me.ActiveControl = -1 Then
-
nmLong = "cbo" & nm & "_Rating"
-
Me(nmLong).Visible = True
-
nmLong = "cbo" & nm & "_Duration"
-
Me(nmLong).Visible = True
-
Else
-
nmLong = "cbo" & nm & "_Rating"
-
Me(nmLong).Visible = False
-
nmLong = "cbo" & nm & "_Duration"
-
Me(nmLong).Visible = False
-
End If
-
-
End If
-
-
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
7 2317
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.
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.
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?
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. - Why doesn't my code work for each update?
- Is there a Form event that will trigger when a (bound) CheckBox value is changed?
Answers- 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.
- 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. - Private Sub ShowHide()
-
Dim strName As String
-
-
With Me
-
If .ActiveControl.ControlType <> acCheckBox Then Exit Sub
-
-
strName = "cbo" & Mid(.ActiveControl.Name, 4)
-
.Controls(strName & "_Rating").Visible = .ActiveControl
-
.Controls(strName & "_Duration").Visible = .ActiveControl
-
End With
-
End Sub
- Private Sub chkName1_AfterUpdate()
-
Call ShowHide()
-
End Sub
-
-
Private Sub chkName2_AfterUpdate()
-
Call ShowHide()
-
End Sub
-
-
Private Sub chkNamen_AfterUpdate()
-
Call ShowHide()
-
End Sub
It's not as tidy as you would have liked, but it's better than full kit and caboodle option.
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!
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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...
|
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...
|
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
{
| |
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?
|
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 +
|
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...
|
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.
|
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,...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |