Same as Previous Date?

J

JMF

I asked a question yesterday - you can see it still on the list - about how
to achieve the effect "Same as Previous" when entering data. That is, take
the default to be whatever the previous value was. I received two great
replies that solved the problem for me:

YourField.DefaultValue = " ' " & [YourField] & " ' "

My field was in fact a text field.

Then I got ambitious and tried to do the same thing for another field, which
happens to be a Date field. I wrote this:

Date.DefaultValue = """" & Date.Value & """"

But, whereas it worked perfectly for my other text field, I got a syntax
error for my Date field.

I'm using the "medium" format for my dates, so that e.g. today is 07-May-06.

I figure I still haven't understood how to work with dates and I'm not
"getting" the syntax.

Could somebody enlighten me?

Thanks!

John
 
A

Arvin Meyer [MVP]

I think your problem may be, at least in part, due to the fact that you've
named the control "Date" which is a reserved word. You can use:

txtDate.DefaultValue = "#" & Me!txtDate & "#"

or

txtDate.DefaultValue = """" & Me!txtDate.Value & """"

Notice the control name for the text box is txtDate, not Date.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
J

JMF

Yes indeed!!

I changed the name of the field to TheDate and that was that: everything
worked like a charm.

Thanks!

John

P.S. So did I understand correctly from your message that "txt" is the
convention people use to prefix fields like this? And while I'm at it: I've
learned that there is frm, tbl, and qry. Is there a similar prefix for a
report? Like maybe "rpt"?

Arvin Meyer said:
I think your problem may be, at least in part, due to the fact that you've
named the control "Date" which is a reserved word. You can use:

txtDate.DefaultValue = "#" & Me!txtDate & "#"

or

txtDate.DefaultValue = """" & Me!txtDate.Value & """"

Notice the control name for the text box is txtDate, not Date.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

JMF said:
I asked a question yesterday - you can see it still on the list - about how
to achieve the effect "Same as Previous" when entering data. That is,
take
the default to be whatever the previous value was. I received two great
replies that solved the problem for me:

YourField.DefaultValue = " ' " & [YourField] & " ' "

My field was in fact a text field.

Then I got ambitious and tried to do the same thing for another field, which
happens to be a Date field. I wrote this:

Date.DefaultValue = """" & Date.Value & """"

But, whereas it worked perfectly for my other text field, I got a syntax
error for my Date field.

I'm using the "medium" format for my dates, so that e.g. today is 07-May-06.

I figure I still haven't understood how to work with dates and I'm not
"getting" the syntax.

Could somebody enlighten me?

Thanks!

John
 
A

Arvin Meyer [MVP]

The field needs no prefix, We do generally prefix controls and objects. My
references below are to a textbox. A field name should describe what the
attribute is, like ContractDate or AcceptanceDate. Yes rpt is the generally
used prefix for a report. I wrote a utility to fix names of objects in
reports and forms. Be careful, not to use it if you already have code
written, or you'll need to change your code to reflect the new object names.

http://www.datastrat.com/Download/FixNames2K.zip

The Leszynski/Reddick Guidelines for Access is the most commonly used naming
convention for Access objects. They are at:

http://www.mvps.org/access/general/gen0012.htm

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

JMF said:
Yes indeed!!

I changed the name of the field to TheDate and that was that: everything
worked like a charm.

Thanks!

John

P.S. So did I understand correctly from your message that "txt" is the
convention people use to prefix fields like this? And while I'm at it: I've
learned that there is frm, tbl, and qry. Is there a similar prefix for a
report? Like maybe "rpt"?

Arvin Meyer said:
I think your problem may be, at least in part, due to the fact that you've
named the control "Date" which is a reserved word. You can use:

txtDate.DefaultValue = "#" & Me!txtDate & "#"

or

txtDate.DefaultValue = """" & Me!txtDate.Value & """"

Notice the control name for the text box is txtDate, not Date.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

JMF said:
I asked a question yesterday - you can see it still on the list - about how
to achieve the effect "Same as Previous" when entering data. That is,
take
the default to be whatever the previous value was. I received two great
replies that solved the problem for me:

YourField.DefaultValue = " ' " & [YourField] & " ' "

My field was in fact a text field.

Then I got ambitious and tried to do the same thing for another field, which
happens to be a Date field. I wrote this:

Date.DefaultValue = """" & Date.Value & """"

But, whereas it worked perfectly for my other text field, I got a syntax
error for my Date field.

I'm using the "medium" format for my dates, so that e.g. today is 07-May-06.

I figure I still haven't understood how to work with dates and I'm not
"getting" the syntax.

Could somebody enlighten me?

Thanks!

John
 

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

Top