Change field of a subfrom while in another subform

  • Thread starter Thread starter vdha via AccessMonster.com
  • Start date Start date
V

vdha via AccessMonster.com

Hello Everybody
I have looked for existing thread on this one but could not find my answer.
Here is my problem

I have a main form and several subforms. One is Review and the other is Date
In the review form I have a button that will send a report but I need to
stamp the date when it was done and all my dates are in the "Date" subform.

SO I need a VB code within the SendReport_OnCLick to go from the review form
to the date form and then do
reviewdate = now()

I tried

Forms. Main.Date.SetFocus (That works)
Me!ReviewDate = Now() (That doesn't work)
Forms. Main.Review.SetFocus

But it doesn't recognize the ReviewDate
I can do this kind of thing if I am within the same form but I have never
been able to perform oprations across different subform.
One more thing, all my subform are based on queries in which I call a common
value on the main form .(don't know if that makes a difference)
Let me know if there is a way.

Thanks
 
you don't need to move focus to the subform to set the value of a field in
that subform's RecordSource. you just need to use the correct references to
the "target" field in your VBA code.

the following code example uses these parameters: the main form is called
frmMain. the review subform is called ChildReview. the date subform is
called ChildDate (if you really named the subform control "Date", recommend
you change it, since Date is a reserved word in Access). the field in the
ChildDate subform is called ReviewDate. the code below runs from within the
ChildReview subform's code module, as

Me.Parent!ChildDate.Form!ReviewDate = Now

you'll have to substitute the correct name of the date subform, and the
correct name of the review date field, of course. and note that you do not
include parentheses when you use the Now function in VBA.

hth
 
Hello Everybody
I have looked for existing thread on this one but could not find my answer.
Here is my problem

I have a main form and several subforms. One is Review and the other is Date
In the review form I have a button that will send a report but I need to
stamp the date when it was done and all my dates are in the "Date" subform.

Just to clarify: They're not "in" the Date subform. They're stored in
some record or records of some table. The Subform is just a *window*
which can display that record (perhaps among many other records); the
form itself is not a data storage repository.
SO I need a VB code within the SendReport_OnCLick to go from the review form
to the date form and then do
reviewdate = now()

I would suggest two things:

1. That you might do better to open a Recordset based on the table,
and edit the table field in that way - rather than trying to update
the Form directly.

2. Quite likely the ReviewDate field should not exist AT ALL, if its
value is redundant with a date stored in the Dates table.
I tried

Forms. Main.Date.SetFocus (That works)
Me!ReviewDate = Now() (That doesn't work)
Forms. Main.Review.SetFocus

If you must do this, try

Forms!Main![Date].Form![ReviewDate] = Now()

Do note that Date is a reserved word - for the current date function
Date() - and as such is a bad choice as a name for an object; and that
Now() does *NOT* return today's date, it returns the current date and
time accurate to microseconds. If you search a field defined using
Now() for a date value such as 4/29/2006, it will return no records
unless the record was entered precisely at midnight.


John W. Vinson[MVP]
 
Thanks Tina but I could not get it to work

Here is what I tried
Me!EditSalesOrder!Scorecard!POMortemDate = Now
Me!Parent!Scorecard!POMortemDate = Now

These are the real name I gave my subforms. I was just maknig it easier for
you
Thanks
you don't need to move focus to the subform to set the value of a field in
that subform's RecordSource. you just need to use the correct references to
the "target" field in your VBA code.

the following code example uses these parameters: the main form is called
frmMain. the review subform is called ChildReview. the date subform is
called ChildDate (if you really named the subform control "Date", recommend
you change it, since Date is a reserved word in Access). the field in the
ChildDate subform is called ReviewDate. the code below runs from within the
ChildReview subform's code module, as

Me.Parent!ChildDate.Form!ReviewDate = Now

you'll have to substitute the correct name of the date subform, and the
correct name of the review date field, of course. and note that you do not
include parentheses when you use the Now function in VBA.

hth
Hello Everybody
I have looked for existing thread on this one but could not find my answer.
[quoted text clipped - 22 lines]
 
Thanks
I don't use the word date, I was just trying to make it easier to follow.
But I didn't that Date could be used.
Thanks

John said:
Hello Everybody
I have looked for existing thread on this one but could not find my answer.
[quoted text clipped - 3 lines]
In the review form I have a button that will send a report but I need to
stamp the date when it was done and all my dates are in the "Date" subform.

Just to clarify: They're not "in" the Date subform. They're stored in
some record or records of some table. The Subform is just a *window*
which can display that record (perhaps among many other records); the
form itself is not a data storage repository.
SO I need a VB code within the SendReport_OnCLick to go from the review form
to the date form and then do
reviewdate = now()

I would suggest two things:

1. That you might do better to open a Recordset based on the table,
and edit the table field in that way - rather than trying to update
the Form directly.

2. Quite likely the ReviewDate field should not exist AT ALL, if its
value is redundant with a date stored in the Dates table.
I tried

Forms. Main.Date.SetFocus (That works)
Me!ReviewDate = Now() (That doesn't work)
Forms. Main.Review.SetFocus

If you must do this, try

Forms!Main![Date].Form![ReviewDate] = Now()

Do note that Date is a reserved word - for the current date function
Date() - and as such is a bad choice as a name for an object; and that
Now() does *NOT* return today's date, it returns the current date and
time accurate to microseconds. If you search a field defined using
Now() for a date value such as 4/29/2006, it will return no records
unless the record was entered precisely at midnight.

John W. Vinson[MVP]
 
go back and look at the syntax i posted, and try using it *exactly as i
posted it*, with the correct subform and field names substituted. and, of
course, you can use Date instead of Now.

hth


vdha via AccessMonster.com said:
Thanks Tina but I could not get it to work

Here is what I tried
Me!EditSalesOrder!Scorecard!POMortemDate = Now
Me!Parent!Scorecard!POMortemDate = Now

These are the real name I gave my subforms. I was just maknig it easier for
you
Thanks
you don't need to move focus to the subform to set the value of a field in
that subform's RecordSource. you just need to use the correct references to
the "target" field in your VBA code.

the following code example uses these parameters: the main form is called
frmMain. the review subform is called ChildReview. the date subform is
called ChildDate (if you really named the subform control "Date", recommend
you change it, since Date is a reserved word in Access). the field in the
ChildDate subform is called ReviewDate. the code below runs from within the
ChildReview subform's code module, as

Me.Parent!ChildDate.Form!ReviewDate = Now

you'll have to substitute the correct name of the date subform, and the
correct name of the review date field, of course. and note that you do not
include parentheses when you use the Now function in VBA.

hth
Hello Everybody
I have looked for existing thread on this one but could not find my
answer.
[quoted text clipped - 22 lines]
 
Thanks Both of you,

I finally used the recordset and got it to work.
Great. Thanks again for this quick help

Thanks
I don't use the word date, I was just trying to make it easier to follow.
But I didn't that Date could be used.
Thanks
[quoted text clipped - 38 lines]
John W. Vinson[MVP]
 
Back
Top