A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Default Value as last date in a table?



 
 
Thread Tools Display Modes
  #1  
Old March 18th, 2010, 05:18 PM posted to microsoft.public.access
Robbro
external usenet poster
 
Posts: 82
Default Default Value as last date in a table?

I have a form that among other things filters a query by a start date and end
date. The start date default value is fixed. The end date field though I
would like the default value to be calculated based on the last date in the
table the query is based on.
I have tried max, dmax, last, and others in the "default value" field and
never can get it right, I always get an error, I'm sure it has somethign to
do with the quotes (I'm quotationally impaired apparently.... )
My table is sales and field is Month End, what exactly do I put in the
default value box to fill this in automatically?
Thanks
  #2  
Old March 18th, 2010, 05:30 PM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Default Value as last date in a table?

Put the DMax for the default of the text box on the form that is bound to
your table field, not in the table.

--
Build a little, test a little.


"Robbro" wrote:

I have a form that among other things filters a query by a start date and end
date. The start date default value is fixed. The end date field though I
would like the default value to be calculated based on the last date in the
table the query is based on.
I have tried max, dmax, last, and others in the "default value" field and
never can get it right, I always get an error, I'm sure it has somethign to
do with the quotes (I'm quotationally impaired apparently.... )
My table is sales and field is Month End, what exactly do I put in the
default value box to fill this in automatically?
Thanks

  #3  
Old March 18th, 2010, 05:37 PM posted to microsoft.public.access
Robbro
external usenet poster
 
Posts: 82
Default Default Value as last date in a table?

yes, that is what I am doing. I can plug a number in manually and it works
as intended, any use of Dmax that I can come up with results in error in the
box instead of the intended date.

"KARL DEWEY" wrote:

Put the DMax for the default of the text box on the form that is bound to
your table field, not in the table.

--
Build a little, test a little.


"Robbro" wrote:

I have a form that among other things filters a query by a start date and end
date. The start date default value is fixed. The end date field though I
would like the default value to be calculated based on the last date in the
table the query is based on.
I have tried max, dmax, last, and others in the "default value" field and
never can get it right, I always get an error, I'm sure it has somethign to
do with the quotes (I'm quotationally impaired apparently.... )
My table is sales and field is Month End, what exactly do I put in the
default value box to fill this in automatically?
Thanks

  #4  
Old March 18th, 2010, 05:50 PM posted to microsoft.public.access
Robbro
external usenet poster
 
Posts: 82
Default Default Value as last date in a table?

NM, finaly got it
DMax("[Month End]","[sales]")

I tried everything but that, the quotes are pure heck in this stuff!

"Robbro" wrote:

yes, that is what I am doing. I can plug a number in manually and it works
as intended, any use of Dmax that I can come up with results in error in the
box instead of the intended date.

"KARL DEWEY" wrote:

Put the DMax for the default of the text box on the form that is bound to
your table field, not in the table.

--
Build a little, test a little.


"Robbro" wrote:

I have a form that among other things filters a query by a start date and end
date. The start date default value is fixed. The end date field though I
would like the default value to be calculated based on the last date in the
table the query is based on.
I have tried max, dmax, last, and others in the "default value" field and
never can get it right, I always get an error, I'm sure it has somethign to
do with the quotes (I'm quotationally impaired apparently.... )
My table is sales and field is Month End, what exactly do I put in the
default value box to fill this in automatically?
Thanks

  #5  
Old March 18th, 2010, 05:59 PM posted to microsoft.public.access
Syed Naqeebullah
external usenet poster
 
Posts: 1
Default Default Value as last date in a table?

jsdfdsjfdjsfjdsjsfndsjcnv


On 3/18/10 10:50 PM, in article
, "Robbro"
wrote:

NM, finaly got it
DMax("[Month End]","[sales]")

I tried everything but that, the quotes are pure heck in this stuff!

"Robbro" wrote:

yes, that is what I am doing. I can plug a number in manually and it works
as intended, any use of Dmax that I can come up with results in error in the
box instead of the intended date.

"KARL DEWEY" wrote:

Put the DMax for the default of the text box on the form that is bound to
your table field, not in the table.

--
Build a little, test a little.


"Robbro" wrote:

I have a form that among other things filters a query by a start date and
end
date. The start date default value is fixed. The end date field though I
would like the default value to be calculated based on the last date in the
table the query is based on.
I have tried max, dmax, last, and others in the "default value" field and
never can get it right, I always get an error, I'm sure it has somethign to
do with the quotes (I'm quotationally impaired apparently.... )
My table is sales and field is Month End, what exactly do I put in the
default value box to fill this in automatically?
Thanks


  #6  
Old March 18th, 2010, 07:02 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Default Value as last date in a table?

On Thu, 18 Mar 2010 10:50:24 -0700, Robbro
wrote:

NM, finaly got it
DMax("[Month End]","[sales]")

I tried everything but that, the quotes are pure heck in this stuff!


They take some getting used to, but the key is that all of the domain
functions (DMax, DLookUp, DCount etc.) take three *text strings* as arguments:
the field to be summed (or looked up or counted); the name of the table or
query in which to look; and an optional third parameter which is a string
containing a valid SQL WHERE clause (without the word WHERE).

These strings can be string literals - in quotes - or string variables, but
they do need to be strings. For instance you could use

Dim strField As String
Dim strTable As String
Dim strCrit as String

strField = "[Month End]"
strTable = "[sales]"
strCrit = "[SalesDate] = #" & DateSerial(Year(Date), 1, 1) & "#"
something = DMax(strField, strTable, strCrit)

would find the maximum value of the Month End field this year to date. This
would give exactly the same results (less readably for the code!) if you use
string literals:

DMax("[Month End]", "[sales]", "[SaleDate] = #1/1/2010#")

--

John W. Vinson [MVP]

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:26 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.