Wrox Programmer Forums
|
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
 
Old April 21st, 2004, 09:20 AM
Authorized User
 
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old April 21st, 2004, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old April 21st, 2004, 01:08 PM
Authorized User
 
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 21st, 2004, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old April 21st, 2004, 03:54 PM
Authorized User
 
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 21st, 2004, 06:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 22nd, 2004, 06:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old April 22nd, 2004, 07:26 AM
Authorized User
 
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 22nd, 2004, 07:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old April 22nd, 2004, 07:34 AM
Authorized User
 
Join Date: Mar 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the field DATE_INV is a DATE type not a text...

Patrica Molard





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing unique record from form to form Baconant Beginning VB 6 1 January 2nd, 2008 06:20 PM
How do I delete a record from a form? dstein4d Access VBA 8 August 24th, 2007 12:09 PM
Search for a record using a form a_wahab Access 6 September 1st, 2006 12:03 PM
ListView record in a form osemollie Pro VB Databases 7 May 19th, 2006 04:05 AM
Adding a record using a form cailos Access 2 October 12th, 2003 11:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.