473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Code to set property in form not working



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
6 3134
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hessam | last post by:
From: "Hessam" <hessammehr@msn.com> Subject: Collection property not working Date: Friday, August 08, 2003 12:24 PM Hello, I am designing a .net custom control in VS.net 7.1 and my control...
0
by: John Hunter | last post by:
I've recently had a nasty problem with the "Invalid reference to the property Form" error in subforms - nasty because it doesn't seem to consistently happen to all forms which contain the same...
4
by: jason | last post by:
i am writing some simple web forms with VB.NET as the code-behind language. the code-behind files import a C# class library namespace from a .dll which is in the references list. however,...
6
by: traversd | last post by:
Hi there, this is driving me nuts! i have a program that is to be run over night, no interaction from the user. I want the code to start runing when the program is started, but i also want to...
4
by: candexis | last post by:
Hi!!!!!!! could you please tell me why this code in not working properly, the thing is that when I read one string after another, the second one is not read, and I don't know why, I am using...
1
by: mistral | last post by:
How to compile javascript code in form of ActiveX control? This will make code more compact and easier to manage on web page. I.e. part of my javascript code already contains activex objects, and i...
31
by: ajos | last post by:
hi frnds, i have a form,which has 2 input text boxes, the values are entering the text boxes,when i leave the 2 text boxes blank and hit submit a java script gives the message that the 2 fields are...
3
by: MyWaterloo | last post by:
I am trying to open my purchase orders form and go to the last record. In the on open command I do: DoCmd.GoToRecord , , acLast Seems straight forward enough...but I keep getting this message...
11
by: wassimdaccache | last post by:
Dear friends I am working on access 2007 sp2. I do have a database(accdb) i converted it to accde. While I am opening the converted database the VBA code is not working. For example...
2
blackgoat
by: blackgoat | last post by:
Hi! Pls help! My code is not working! Pls tell me whats wrong with it... it returns value 1 in all cases!! %dbase = { apple => "fruit", brinjal => "vegetable" , ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.