473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3137
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
1132
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
1007
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
1452
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
3822
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
2781
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
2232
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
15306
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
10864
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
24893
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
1324
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
7202
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
7086
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
7280
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,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.