Hello,
I have a drop down menu with four items. Then below that I have a check box and a date field. Currently if you are to click on the checkbox the date field updates with today's date.
However I would like it if a user checks the third option down "Contract Delivered" to then update the checkbox. Check itself which then will also update the date field.
Here is my logic and I'm new to VBA Access, so any help in regards to syntax or logic is greatly appreciated. -
-
Private Sub substatus_AfterUpdate()
-
If Status = 3 Then
-
Me.Check198 = -1
-
End If
-
End Sub
-
-
The above code is in the AfterUpdate event of my drop down field, I have also placed it under the Click event and no luck.
Here is my code for the check box which works fine: -
Private Sub Check198_AfterUpdate()
-
On Error GoTo Err_Check198_AfterUpdate
-
If [Check198] = -1 Then
-
Me.assignedtoRep = Now()
-
Me.[SubStatus] = 4
-
End If
-
DoCmd.Requery "SubStatus"
-
DoCmd.Requery "assignedtorep"
-
Exit_Check198_AfterUpdate:
-
Exit Sub
-
-
Err_Check198_AfterUpdate:
-
MsgBox Err.Description
-
Resume Exit_Check198_AfterUpdate
-
-
End Sub
-
12 5776
The AfterUpdate event for the check box will not fire as a result of setting the check box's status programmatically. You need to set the date field manually: - Private Sub substatus_AfterUpdate()
-
If Status = 3 Then
-
Me.Check198 = -1
-
Me.assignedtoRep = Now()
-
End If
-
End Sub
As a side note and completely optional but highly suggested piece of advice, give your controls sensible names. If your project grows to anything beyond the simplest form, you'll be happy that you did.
Pat
Pat,
Thank you so much for the help. So you're saying that even if the code worked and the check box was clicked it will not set off the date.. I was not aware. Also thank you for your advice I will make sure to get better names on the controls and labels.
I've tried the code above but it does not seems to work. Would I be better placing this code in a different event such as On Change or On Click or is this the right event?
Also I was just guessing on the Status = 3 and Me.Check198 = -1. Will that choose the third item from the drop down list and will that -1 set the check box to marked. None of those are happening.
And do I need to perhaps mess with or add
to the code?
The check box AfterUpdate event will fire only if the user actually clicks the check box. This is my understanding of how the event works, and I tested it in my sandbox database. The other experts might have more insight into this matter than I do.
As for making a selection from the combo box...that code should work. Where does this variable "Status" come into the picture? I don't see it defined anywhere, and you're not showing where it gets its value from...I think this may be the crux of the problem.
Pat
Pat,
You're right, the check box only works if it is clicked then the date shows up. I want to see if I can have the program check it and then fill in the date once the third option from the dropdown menu Substatus has been selected.
And you just pointed out a flaw, Status is another drop down menu above Substatus drop down menu. Status has no relevance. So should my code be
It does not work but I think that's what it should be unless Status is a function in VBA.
Pat,
Here's my latest code, I feel like were getting closer but it does not work: - Private Sub substatus_AfterUpdate()
-
-
If Me.SubStatus = 3 Then
-
-
Me.ContractDeliverd = -1
-
Me.DeliveredDate = Now()
-
-
End Sub
Just before the If text, put this:
This will tell you what value the combo box is actually returning. If it's not "3", and in particular if it's not even a number, then it should be instructive as to what is happening here.
Pat,
Nothing happened, here is my code: -
Private Sub substatus_AfterUpdate()
-
MsgBox Me.SubStatus
-
If Me.SubStatus = 3 Then
-
-
Me.ContractDeliverd = -1
-
Me.DeliveredDate = Now()
-
-
DoCmd.Requery "substatus"
-
Exit_substatus_AfterUpdate
-
-
End Sub
Is there a way to check another way instead of "3" maybe the text?
Are you making sure to re-compile every time you make a modification in the code?
Pat,
I just found out that I needed to compile. The compile button was never added to my VBA layout and I had no idea I needed to compile each time. So after a few too many compile errors and getting around them it seems that some of my code was lost when I opened the ".accdr" file. I am re writing all my updates and will put in the above code, compile and see if it works. Thank you for that btw!
It's actually in the Debug menu up top. Another debugging tip for you to look into is the concept of breakpoints, which stops the code execution at an executable line that you pick out ahead of time.
I'm getting ready to leave the office. I will check back in with the thread later tonight or in the morning.
Learning is great. I have followed your instructions from the post about variable declaration.I will debug all weekend and come back to this post once I debug. Thank you both
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andy Fish |
last post by:
Hi,
Part of my web form allows the user to select their favourite color (well it
doesn't but it's a good example).
There is a dropdown box with red, green, blue, and custom. When they click...
|
by: |
last post by:
hi,
selected items in check box disappears when submit button is clicked on aspx
page. check box is pasted on .ascx page and which is pasted on aspx page
any ideals
cheers
sam
|
by: Big Dave |
last post by:
I know it's been asked a million times before, but I still can't seem to
find an answer that works.
I've got a dropdown list in the footer template of a datagrid. The
dropdown list databinds,...
|
by: Rudy Ko |
last post by:
Hi,
I seem unable to set the selected item in a DropDownList by using the
following code, it always return the toppest (index 0) item, no matter what
i selected.
list.DataSource =...
|
by: dev.amit |
last post by:
Hello friends
Can anyone tell me how to deselect the item selected in the list box
If Me!lb_test_property.ItemsSelected.Count > 0 Then
For Each varItem In Me!lb_test_property.ItemsSelected...
|
by: SA SA |
last post by:
Is this possible? I have three items in drop down "Select Payment
Type", "Credit Card" and "Check". if user select Credit card then i
need to post the form variables to different URL than check...
|
by: imran |
last post by:
Dear All,
I am developing web Application using asp.net and C#(VS2005).i want to know
how i can fetch menu item selected(which is desinged in master.aspx) on the
other C# page (welcome.aspx.cs).
|
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= |
last post by:
Hello.
I am reading a value from a table and trying to determine if that value
exists in a list of values associated with a dropdownlist. If so, I select
the value, otherwise, I don't. I haven't...
|
by: lalit |
last post by:
Can some one please tell me how to make a specuific item selected in
dropdwonlist
my dropdwonlist is bounded with a database table getting something
like this:
<tr>
<td >
Client Name</td>
<td...
|
by: coldfusionstudent |
last post by:
i wish to show/appear and dissappear text box based on a the drop down item selected.
what do i have to add?
thanks
under Comm_DEV
drop down selection.
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: 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...
| |