 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 21st, 2004, 09:20 AM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Keep last record in a form
Hi,
I developp a form to enter data and I want to keep in memory the last enter of the date for each record (the date is not the date of the current day, it's the date the empoyee did the job or cancelled it). My form is something like this:
EMPLOYEE1 (a drop downlist)
EMPLOYEE2 (a drop downlist)
REALIZED (a check button)
CANCELLED (a check button)
DATE (a text box, format: date like this 2004-06-06): that's this one I want to keep the value in mind for the next record.
What is the simplest way to do it ? Is it in VB or I'm abble to do it with a macro ? Anyway I need your help in both ways.
Tanks
Patricia
Patrica Molard
__________________
Patrica Molard
|
|

April 21st, 2004, 11:05 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
First, don't call the date field DATE. The word "Date" is a reserved function in Access. You may confuse the computer. Let's call it, for example, ActionDate.
Put this in the form's ON OPEN event:
Me.ActionDate.DefaultValue = DMax("[ActionDate]", "Your Table Name", "[ActionDate] Is Not Null")
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

April 21st, 2004, 01:08 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks,
I tried your code but it does nothing in my case.
I'm working in a sub-form, is-it important ?
I tried in a "flat form" related to one table and it works but it put this date: 1905-06-14... I guess this is my default value.
I actually working in french and in my case the field's name for this date is DATE_INV. The other field's name are: EVALUATEUR1,EVALUATEUR2,REALISEE,ANNULE. The table's name is Placettes, so I put this line at the ON OPEN event for the sub-form (which fill the table Placettes):
Me.DATE_INV.DefaultValue = DMax("[DATE_INV]", "Placettes", "[DATE_INV] Is Not Null")
Do I have to write something for the form which is working with the sub-form ?
Patrica Molard
|
|

April 21st, 2004, 03:10 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Hmmm... you seem to have put it in the right place... The subform is where you want it. Try this one:
Me.DATE_INV.DefaultValue = DMax("[DATE_INV]", "Placettes", "[DATE_INV] <= #" & Date() & "#")
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

April 21st, 2004, 03:54 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried your last code in both form and It says in french: "Utilisation incorrecte du NULL" so in English, "Wrong Utility of NULL"
Patrica Molard
|
|

April 21st, 2004, 06:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
or "Invalid Use of Null"
Does your "Placettes" table have any records in it already?
I am a loud man with a very large hat. This means I am in charge
|
|

April 22nd, 2004, 06:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Quote:
quote:Originally posted by Steven
Does your "Placettes" table have any records in it already?
|
Good question. That code should work and not have any problems with NULL unless the table "Placettes" is empty.
Try:
Me.DATE_INV.DefaultValue = Nz(DMax("[DATE_INV]", _
"Placettes", "[DATE_INV] <= #" & Date() & "#"),Date())
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

April 22nd, 2004, 07:26 AM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried this code it's working but it gave me this date : 1905-05-31
I had already 2 dates in the table Placettes: 2004-06-06 and 2004-06-08. So it should put 2004-06-08 (the last one)
Patrica Molard
|
|

April 22nd, 2004, 07:32 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
I'm curious... is your date field set as a datatype DATE and not TEXT? If so, it could be messing up the functions.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

April 22nd, 2004, 07:34 AM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
the field DATE_INV is a DATE type not a text...
Patrica Molard
|
|
 |