Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateAdd fun. as default value on a bound txtbox?

Status
Not open for further replies.

broj1

Technical User
Dec 13, 2007
27
EU
hi
i have a bound txtfield1 where user enter date with calendar form
then i have a txtfield2 where the default value should be
= DateAdd("d";-2;[txtfield1])
but with possibility to enter date also with calendar form.
It is bound control... so i guess that is why it is not working.
How to change this so it will work.

thanks
 
the problem is:
when i put this function on default control of txtbox = DateAdd("d";-2;[txtfield1])
it does nothing, but should get some date from txtfield1 -2.
both txtboxes are bound, couse there have to be an option of manual entry
 
Just as a starting point DateAdd() uses comma's for seperators as opposed to semi-colons. I'm assuming that's a typo?

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
no, it doesn't allow me to put comma's, so i assume that semi-colons are fine (i don't get any error) it just don't display - nothing
 
So you say that for the second box, the "default value" is based on the first text box; does this mean that you have the formula in the "DEFAULT VALUE" property? If so, Default Value only fills in when you add a new record.

How about this instead: you say that a user can either pick the Date2 from a calendar, or have Date2 fill in with the DateAdd function. How about putting some code in the DoubleClick property of Date2 text box, so the user can just double-click it and it will fill in the date depending on what is in Date1 (In the Double-Click property, pick EVENT PROCEDURE and click the BUILD BUTTON (the little button to the right with the three dots on it) and paste this in):

Code:
If Not IsNull(Me.txtField1) Then Me.txtField2 = DateAdd("d", -2, Me.txtField1)




Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
GingerR

yes, this looks like a nice solution, but what about then when user inputs the date with the calendar ...whatever dates he inputs it has to be -2 days?
What should i do then?
 
huh?

Originally you said
but with possibility to enter date also with calendar form

Not sure what you mean?

I think that what you mean is this:

You have TextBox1 and TextBox2

A user types a date into TextBox1, either by typing on the keyboard or by picking a date from a calendar. You then want TextBox2 to either reflect 2 days before TextBox1, OR the user can just pick a date from a calendar to fill in TextBox2.

If this isn't correct, then please explain better what you are looking for. What about my suggested solution isn't working? Have you tried other things? Do they work or not, and how?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
You must separate arguments in a function with commas, not semi-colons! Access is inserting the semi-colons because it's confused about what you're doing. As Ginger said, Default Values are inserted when a new record is started. Since no controls have data in them when a new record is invoked, you can't refer to a control in a Default Value! At the point the Default Value would be inserted, txtfield 1 has no value!

As with Ginger, your explanation of what you're trying to do seems rather muddled to me, but I think you mean to say that you want to enter a date in txtfield1 either manually or with a calendar control, then you want the value in txtfield2 to be that date -2. If this is so, what you need to do is use code like this:

Code:
Private Sub txtfield1_AfterUpdate()
 Me.txtfield2 = DateAdd("d", -2, Me.txtfield1)
End Sub

Private Sub YourCalendarName_Click()
 Me.txtfield1 = Me.YourCalendarName
 Me.txtfield2 = DateAdd("d", -2, Me.YourCalendarName)
End Sub

This will assign the value of txtfield1 - 2 days to txtfield2 whether txtfield1 is entered manually or with a calendar.

Note that because (I assume) the calendar you're using is an ActiveX control, all of its properties aren't available theu the Property Box. So to enter the second piece of code above, you have to go into the code window then use the dropdown box to get the Sub YourCalendarName_Click() in code.

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Nods in agreement with missinglinq, commas.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I don't think the commas are the issue any more. I think it's getting a clear explanation of what s/he wants.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
yes, sorry i wasn't clear!
the code for dblcl event works, but my original idea is
when new record is created, all fields are blank, couse all get values after txtbox1 is filled(with date picked from calendar)
other let.us.say txtbox2 then should get defaullt value based on what is in txtbox1 -- (date -2) or if this is not right for the user he can still pick one from calendar if not setisfied with default

calendars and all is working accept to put in the default value based on txtbox1 with fun.= DateAdd("d";-2;[txtfield1])
is not working
 
Ok, you now say "calendars and all is working" - so are you saying is that in DATE TEXT BOX 1, you can pick from a calendar control or you can type a date directly into that box? I think this is what you are saying, which is just what you were saying at the beginning of this string.

Ok, then, does DATE TEXT BOX 2 work if you double-click it? It sort of seems like you say that it does in your last post. I have to say again IT WILL NEVER WORK IN THE DEFAULT PROPERTY so please give that idea up. IT WILL NEVER WORK!! Take it out!!!

Are there more than one text box that you want filled in based on DATE TEXT BOX 2? This sentence leads me to believe that there are:

all fields are blank, couse all get values after txtbox1 is filled

You have to use AfterUpdate of DATE TEXT BOX 1 and write code to then go thru all of your other controls and fill them in with whatever dates you wish. See Missinglinq's post above.



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 

Actually, if you want the option of entering the date into txtfield1 manually or entering the date thru a calendar, you have to use the Click event of the calendar as well. If txtfield1 is populated by using the calendar, its AfterUpdate event won't fire. AfterUpdate only fires if data is manually entered into a control.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
hi fellaz,

i have been of for few days. Thanks for your replays.

You are both right. I will try to work around this, but may need additional help later. I will let you know how it goes.
thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top