By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

Code to set property in form not working

P: n/a


I have 2 forms, an unbound which calls a bound form via a command
button. Both forms have a textbox called TDate. The name of the
calling form is SelectionFrm. When I set the DefaultValue property of
the textbox on the called form to:

=[Forms]![SelectionFrm]![TDate]

I get exactly what I want in TDate on the called form.

But if I remove this from the properties and put the following code in
for the called form's open form event, it doesn't work:

Me.TDate.DefaultValue = [Forms]![SelectionFrm]![TDate]

I put a stop right after this statement. The value of
Me.TDate.DefaultValue shows correctly at that point. But on the screen
it comes up as '12/30/1899'.

I also tried putting it in the BeforeUpdate event of TDate. That didn't
work either.

Any idea why the code doesn't work while the property does? Or is it
impossible to set default values in code?

Robert
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The Default Value property is text, regardless of what the value is. Try:

Me.TDate.DefaultValue = "" & [Forms]![SelectionFrm]![TDate] & ""

or

Me.TDate.DefaultValue = Chr$(34) & [Forms]![SelectionFrm]![TDate] & Chr$(34)
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Robert C" <pr**********@yahoo.com> wrote in message
news:40*********************@news.frii.net...


I have 2 forms, an unbound which calls a bound form via a command
button. Both forms have a textbox called TDate. The name of the
calling form is SelectionFrm. When I set the DefaultValue property of
the textbox on the called form to:

=[Forms]![SelectionFrm]![TDate]

I get exactly what I want in TDate on the called form.

But if I remove this from the properties and put the following code in
for the called form's open form event, it doesn't work:

Me.TDate.DefaultValue = [Forms]![SelectionFrm]![TDate]

I put a stop right after this statement. The value of
Me.TDate.DefaultValue shows correctly at that point. But on the screen
it comes up as '12/30/1899'.

I also tried putting it in the BeforeUpdate event of TDate. That didn't
work either.

Any idea why the code doesn't work while the property does? Or is it
impossible to set default values in code?

Robert
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2

P: n/a
Robert C <pr**********@yahoo.com> wrote in
news:40*********************@news.frii.net:


I have 2 forms, an unbound which calls a bound form via a
command button. Both forms have a textbox called TDate. The
name of the calling form is SelectionFrm. When I set the
DefaultValue property of the textbox on the called form to:

=[Forms]![SelectionFrm]![TDate]

I get exactly what I want in TDate on the called form.

But if I remove this from the properties and put the following
code in for the called form's open form event, it doesn't
work:

Me.TDate.DefaultValue = [Forms]![SelectionFrm]![TDate]

I put a stop right after this statement. The value of
Me.TDate.DefaultValue shows correctly at that point. But on
the screen it comes up as '12/30/1899'.

I also tried putting it in the BeforeUpdate event of TDate.
That didn't work either.

Any idea why the code doesn't work while the property does?
That's because the code fires after the control has been set on the
form.
Or is it impossible to set default values in code?
It's pretty well useless to set default values in code. Your form
will work quite well just setting Me.Tdate.value if you are
creating a new record.

Bob Quintal

Robert
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #3

P: n/a
This works in the current event:

If Me.NewRecord Then
Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
End If

The DefaultValue works when I put it in on the screen, so why not in code?
It would be nice to know, anyway, even if the form is working okay now.

Robert C

"Bob Quintal" <bq******@generation.net> wrote in message
news:95******************************@news.teranew s.com...
Robert C <pr**********@yahoo.com> wrote in
news:40*********************@news.frii.net:


I have 2 forms, an unbound which calls a bound form via a
command button. Both forms have a textbox called TDate. The
name of the calling form is SelectionFrm. When I set the
DefaultValue property of the textbox on the called form to:

=[Forms]![SelectionFrm]![TDate]

I get exactly what I want in TDate on the called form.

But if I remove this from the properties and put the following
code in for the called form's open form event, it doesn't
work:

Me.TDate.DefaultValue = [Forms]![SelectionFrm]![TDate]

I put a stop right after this statement. The value of
Me.TDate.DefaultValue shows correctly at that point. But on
the screen it comes up as '12/30/1899'.

I also tried putting it in the BeforeUpdate event of TDate.
That didn't work either.

Any idea why the code doesn't work while the property does?


That's because the code fires after the control has been set on the
form.
Or is it impossible to set default values in code?


It's pretty well useless to set default values in code. Your form
will work quite well just setting Me.Tdate.value if you are
creating a new record.

Bob Quintal

Robert
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #4

P: n/a
This produces the same result. I am using a work-around now. Thanks for
your help.
Robert
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:BJ*******************@news04.bloor.is.net.cab le.rogers.com...
The Default Value property is text, regardless of what the value is. Try:

Me.TDate.DefaultValue = "" & [Forms]![SelectionFrm]![TDate] & ""

or

Me.TDate.DefaultValue = Chr$(34) & [Forms]![SelectionFrm]![TDate] & Chr$(34)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Robert C" <pr**********@yahoo.com> wrote in message
news:40*********************@news.frii.net...


I have 2 forms, an unbound which calls a bound form via a command
button. Both forms have a textbox called TDate. The name of the
calling form is SelectionFrm. When I set the DefaultValue property of
the textbox on the called form to:

=[Forms]![SelectionFrm]![TDate]

I get exactly what I want in TDate on the called form.

But if I remove this from the properties and put the following code in
for the called form's open form event, it doesn't work:

Me.TDate.DefaultValue = [Forms]![SelectionFrm]![TDate]

I put a stop right after this statement. The value of
Me.TDate.DefaultValue shows correctly at that point. But on the screen
it comes up as '12/30/1899'.

I also tried putting it in the BeforeUpdate event of TDate. That didn't
work either.

Any idea why the code doesn't work while the property does? Or is it
impossible to set default values in code?

Robert
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #5

P: n/a
"Robert" <pr**********@yahoo.com> wrote in
news:10*************@corp.supernews.com:
This works in the current event:

If Me.NewRecord Then
Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
End If

The DefaultValue works when I put it in on the screen, so why
not in code? It would be nice to know, anyway, even if the
form is working okay now.

Robert C


Think about the sequence of the events that occur when you click on
the button to open your new form.

The first thing that happens is that Access opens the form.
Second it moves to eof,(the new record),
third thing it does is it fills in the fields from the default
values,
Lastly it then execudes your code that changes the default values.

Everything is working as it should, but it's too late for the
record shown on the screen.

That's why I said that changing .defaultvalue in code is pretty
useless.

The next new record would show the amended defaultvalue, as long as
you don't close the form between each addition.

That's why I didn't say 'totally useless'.

Bob Q.

Nov 12 '05 #6

P: n/a
Okay, I understand now.

"Bob Quintal" <bq******@generation.net> wrote in message
news:b6******************************@news.teranew s.com...
"Robert" <pr**********@yahoo.com> wrote in
news:10*************@corp.supernews.com:
This works in the current event:

If Me.NewRecord Then
Me.TDate.Value = [Forms]![SelectionFrm]![TDate]
End If

The DefaultValue works when I put it in on the screen, so why
not in code? It would be nice to know, anyway, even if the
form is working okay now.

Robert C


Think about the sequence of the events that occur when you click on
the button to open your new form.

The first thing that happens is that Access opens the form.
Second it moves to eof,(the new record),
third thing it does is it fills in the fields from the default
values,
Lastly it then execudes your code that changes the default values.

Everything is working as it should, but it's too late for the
record shown on the screen.

That's why I said that changing .defaultvalue in code is pretty
useless.

The next new record would show the amended defaultvalue, as long as
you don't close the form between each addition.

That's why I didn't say 'totally useless'.

Bob Q.

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.