PDA

View Full Version : set date field on subform to date variable



Laavista
06-30-2010, 06:21 AM
I need to set a date field on a sub form to a date variable.

- Parent form is called "f_Advertise"

- Have sub_form called "f_Advertise subform"

- Field on the sub_form called "PostedDate" (date, short)

- Have a variable called "NewPostedDate", (dim as date), e.g., 07/19/2010



I tried the following things:

1) me.PostedDate = NewPostedDate (got error message)

2) me.PostedDate = (# NewPostedDate #) (got error message)

3) me.PostedDate.DefaultValue = NewPostedDate (no error message, but
PostedDate field did not display the new date)

4) me.PostedDate.DefaultValue = NewPostedDate
If me.Dirty=true then me.dirty=false
(no error message, but PostedDate field did not display the new date)

5) tried putting NewPostedDate variable as the default value in the field's property. It translated the entry as "NewPostedDate"

Your help would be greatly appreciated!

OBP
06-30-2010, 10:54 AM
Laavista, have you checked that your Variable is holding the date when you try and pass it to the Date field?
As me.PostedDate = NewPostedDate should work Ok providing the date is in the correct format.
Try adding
msgbox NewPostedDate

Laavista
06-30-2010, 12:27 PM
Thanks for the idea, but I have checked and it the variable does contain the date I need.

After update of another date field, I used a procedure to call a function that adds a number of working days to the beginning date. I need to display that date in the field "PostedDate". The variable (NewPostedDate) containing the new date does have the correct date, in the right format.

Laavista
06-30-2010, 12:58 PM
Perhaps if I explain what I'm doing it may help?

Parent form: f_lca
sub_form: f_Advertise subform

1st field on sub form called "StartOfPost" (date, short)
User enters a Start Posted date
After this date is entered, in the after_update event, I call a function
that adds working days to this date and passes back a new date in
a variable called "NewPostedDate"

2nd field on sub form called "PostedDate" (date, short). I need to display the contents of the variable "NewPostedDate" in this field. The user may wish to change it, but it needs to display the new date.

I checked the variable "NewPostedDate" and it does have a date value in the right format. (e.g., 7/19/2010)

I did try formatting the date using format(NewPostedDate, "mm/dd/yy") but it did not change the date.

I also tried the following:

me![f_lca]!form![PostedDate] = tempnewdate 'error msg can't find field referred to (I DOUBLECHECKED the field name in properties and it IS PostedDate)

me![f_advertise subform].form![PostedDate].value = tempnewdate 'can't find field referred to.

forms!f_lca![f_advertise subform].form![PostedDate] = tempdate 'field is too small to accept amount of data entered. (I doublechecked that the format was correct in the variable)

me![f_lca]![posteddate] = tempnewdate 'can't find field referred to

Thanks for your help.

OBP
07-01-2010, 05:48 AM
Can you attach a czipped copy of the database in Access 2000-2003 format for me to look at?
Getting the subform and field names are crucial and the response to this version is interesting
forms!f_lca![f_advertise subform].form![PostedDate] = tempdate 'field is too small to accept amount of data entered. (I doublechecked that the format was correct in the variable)
as it doesn't say it can't find the field.

Laavista
07-01-2010, 08:57 PM
Thanks so much for your help. I found out that my field had somehow got corrupted? I deleted it from the form and added it back in, and it worked?? I've never had that happen before (and it will be one of the first things I check in the future if I get wierd errors).