Default Value as last date in a table?

R

Robbro

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
 
K

KARL DEWEY

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

Robbro

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.
 
R

Robbro

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

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

Syed Naqeebullah

jsdfdsjfdjsfjdsjsfndsjcnv


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

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

Robbro said:
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.
 
J

John W. Vinson

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#")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top