MS Access Forum / New Users / March 2006
Forcing the Current Date into a Form Field when a Checkbox is Clic
|
|
Thread rating:  |
SkyGuy - 24 Feb 2006 15:51 GMT Hello,
I'm new to Access and not familiar with Events, Procedures or Visual Basic.
I have a form with a Date Field called "Expiration Date". In the same form I have a Checkbox called "Terminated".
I'd like the current date to automatically populate the Expiration Date when Terminated is checked.
Any help would be very much appreciated.
Thanks, Bob
Ed Robichaud - 24 Feb 2006 16:02 GMT In the AfterUpdate event of your checkbox, put:
If Me.[Terminated] = -1 then Me.[Expiration Date] = Date() End if
-Ed
> Hello, > [quoted text clipped - 13 lines] > Thanks, > Bob SkyGuy - 24 Feb 2006 16:18 GMT I apologize Ed...Terminated is not a Checkbox. It's a Selection List with either a value of Yes or No. So if I select Yes in Terminated I want the Experiation field to be populated with today's date. Again, sorry for the initial misinformation. Bob
> In the AfterUpdate event of your checkbox, put: > [quoted text clipped - 21 lines] > > Thanks, > > Bob Ed Robichaud - 24 Feb 2006 17:15 GMT OK, just change it to:
If Me.[Terminated] = "Yes" Then Me.[Expiration Date] = Date() End if
>I apologize Ed...Terminated is not a Checkbox. It's a Selection List with > either a value of Yes or No. So if I select Yes in Terminated I want the [quoted text clipped - 28 lines] >> > Thanks, >> > Bob SkyGuy - 24 Feb 2006 18:06 GMT Ok Ed...I right-clicked on the form's Terminated field in Design View then choice Build Event. I then chose "After Update" from the drop-down list in Visual Basic. But when I do a save Visual Basic eliminates the () after =Date and the solution does not work. What am I doing wrong...thanks.
> OK, just change it to: > [quoted text clipped - 34 lines] > >> > Thanks, > >> > Bob Gina Whipp - 28 Feb 2006 14:19 GMT My 2 cents worth...
You said you went to ' form's Terminated field in Design View then ' (you just want to make sure it's not on the After Update of the form because it needs to be on the After Update of the control)
Okay not sure the code is in the correct place, so just check
1. Go to Design View on the form 2. Go click on you field ' Terminated ' and then right mouse click if Properties Window for your field is not showing and select Properties. 3. In the Properties Window for your field scroll down till you find the After Update Event and select ... Build Event 4. Place your code, close and save. Try it, if that does not work post back.
If you have already done the above "NEVERMIND"
The () after Date sometime disappears on mine to, still does wht it's suppose to.
Gina
> choice Build Event"SkyGuy" <SkyGuy@discussions.microsoft.com> wrote in > message news:72F0B88E-EF39-4E5A-972D-2C367E9B9334@microsoft.com... [quoted text clipped - 47 lines] >> >> > Thanks, >> >> > Bob SkyGuy - 28 Feb 2006 16:07 GMT Gina,
I replied to your post but it looks like it didn't take. So here's another post. First of all...thanks for your help...but my Date field is still not populating.
I'm using MS Access 2002.
In Design View, I right-clicked on the Terminated Field, selected Properties, then scrolled down to After Update and clicked on the drop-down arrow. There was only one choice; [Event Procedure]. I selected this then clicked on the elipses button to the right. A windows opened and I pasted my code just below the "Private Sub Terminated_AfterUpdate()" and did a save.
Here's a copy of my code:
Private Sub Terminated_AfterUpdate()
If Me.[Terminated] = "Yes" Then Me.[Expiry Date] = Date End If
End Sub
Thanks again, Bob
> My 2 cents worth... > [quoted text clipped - 70 lines] > >> >> > Thanks, > >> >> > Bob Gina Whipp - 28 Feb 2006 16:26 GMT You Expiry Date, is it a combo box and is it just 1 column?
> Gina, > [quoted text clipped - 107 lines] >> >> >> > Thanks, >> >> >> > Bob Gina Whipp - 28 Feb 2006 16:32 GMT Please try pasting the below code and then change the combo box. Does a message come up?
If Me.Terminated = "Yes" Then 'Me.[Expiry Date] = Date MsgBox "Yes, I work!", vbOkOnly, "Test" Else MsgBox "No, I don't work!", vbOkOnly, "Test" End If
> Gina, > [quoted text clipped - 107 lines] >> >> >> > Thanks, >> >> >> > Bob SkyGuy - 28 Feb 2006 17:16 GMT Gina,
A pop-up msg appeared that said "No, I don't work!". That was cool. But obviously I still have a problem.
Bob
> Please try pasting the below code and then change the combo box. Does a > message come up? [quoted text clipped - 117 lines] > >> >> >> > Thanks, > >> >> >> > Bob Gina Whipp - 28 Feb 2006 17:35 GMT Okay but at least we now know the code is being read! Your combo box, is that a single row not 2 row
1;Yes 2;No
and the bound column is 1?
Please look at the Property Window of Terminated, what you should see is Column Count = 1 and Bound Column = 1 and Row Source = Yes;No and Row Source Type = Value List.
> Gina, > [quoted text clipped - 138 lines] >> >> >> >> > Thanks, >> >> >> >> > Bob SkyGuy - 28 Feb 2006 18:08 GMT Bound Column: 1 Column Count: 1 Row Source: Yes;No Row Source Type: Value List
I'm not sure what you mean by combo box. But on the form, Terminated is a selection list w/either a value of No or Yes. So I guess the correct answer to your first question is 2 rows.
> Okay but at least we now know the code is being read! Your combo box, is > that a single row not 2 row [quoted text clipped - 150 lines] > >> >> >> >> > Thanks, > >> >> >> >> > Bob Gina Whipp - 28 Feb 2006 18:41 GMT Selection LIst? You mean it's NOT a combo box? Combo Box has a little arrow where you select from a list.
> Bound Column: 1 > Column Count: 1 [quoted text clipped - 174 lines] >> >> >> >> >> > Thanks, >> >> >> >> >> > Bob SkyGuy - 28 Feb 2006 20:41 GMT Yes Gina, the Terminated form field has a little arrow to select from a list. So it is a combo box. Sorry for the mix up in terminology...I'm new to this.
Bob
> Selection LIst? You mean it's NOT a combo box? Combo Box has a little > arrow where you select from a list. [quoted text clipped - 177 lines] > >> >> >> >> >> > Thanks, > >> >> >> >> >> > Bob John Spencer - 28 Feb 2006 20:53 GMT Pardon me, but I think that the Row source being Yes; No might end up being True/False when you are testing the value.
Using your earlier test technique
Msgbox "The value is " & me.terminated
IF the message comes back The value is -1 or The value is 0 then you probably are returning true and false.
If the message is The value is <blank> then you know that somehow your combobox is not retaining the value.
> Yes Gina, the Terminated form field has a little arrow to select from a > list. [quoted text clipped - 204 lines] >> >> >> >> >> >> > Thanks, >> >> >> >> >> >> > Bob SkyGuy - 02 Mar 2006 21:17 GMT Ok...here's my current code, which is working (somewhat). I change Terminated from "No" to "Yes" and Expiry Date remains blank. But after after I move to the next/previous record, then go back to the record that I set Terminated to "Yes", the Expiry Date will display the current date.
Private Sub Terminated_Change() If Me.Terminated = "-1" Then Me![Expiry Date].Value = Now() MsgBox "Yes, I work!", vbOKOnly, "Test" Else MsgBox "No, I don't work!", vbOKOnly, "Test" End If
End Sub
> Pardon me, but I think that the Row source being Yes; No might end up being > True/False when you are testing the value. [quoted text clipped - 219 lines] > >> >> >> >> >> >> > Thanks, > >> >> >> >> >> >> > Bob Gina Whipp - 03 Mar 2006 03:18 GMT Try putting the code on the After Update of the combo box and on the On Current of the form.
> Ok...here's my current code, which is working (somewhat). I change > Terminated [quoted text clipped - 257 lines] >> >> >> >> >> >> >> > Thanks, >> >> >> >> >> >> >> > Bob John Spencer - 03 Mar 2006 15:23 GMT Do you have a control bound to the field? What is the name of the control?
I would try
Me.[Expiry Date] = Now()
Also, you do know that Now() will return the date AND the time? If you want just the date then use
Me.[Expiry Date] = Date()
> Ok...here's my current code, which is working (somewhat). I change > Terminated [quoted text clipped - 257 lines] >> >> >> >> >> >> >> > Thanks, >> >> >> >> >> >> >> > Bob SkyGuy - 28 Feb 2006 13:25 GMT So after I paste the code below in the VB windows and save the parenthesis after the =Date() disappear. And the Experation Date does not populate w/Today's Date when the Termintated Selection List is changed to "Yes".
Any suggestions?
> OK, just change it to: > [quoted text clipped - 34 lines] > >> > Thanks, > >> > Bob Gina Whipp - 01 Mar 2006 00:22 GMT And check the time on your PC seems to be acting a little weird, says you posted this message at 8:25am???
> So after I paste the code below in the VB windows and save the parenthesis > after the =Date() disappear. And the Experation Date does not populate [quoted text clipped - 45 lines] >> >> > Thanks, >> >> > Bob Gina Whipp - 01 Mar 2006 00:22 GMT Do you try what John suggested, he has a point!
> So after I paste the code below in the VB windows and save the parenthesis > after the =Date() disappear. And the Experation Date does not populate [quoted text clipped - 45 lines] >> >> > Thanks, >> >> > Bob
|
|
|