Set control

T

Tru

Scenario: My Main Form (Parent Form) has a bound text control on it called
txtDateClosed that the user is not permitted to access. The only way this
field can be completed if they Click a command button on the Parent Form to
open the other form (Child Form) and complete the required information on the
Child Form. Once the required information is completed which includes the
date information for txtDateClose on the Parent Form. I am trying to transfer
the txtCloseDate on the Child Form to the txtDateClosed on the Parent Form
but nothing is happening, I'm not getting no error messages either, below is
the code I am using:

Dim Ctl As Control

'If Parent Form is loaded, select it, and set value
'of selected text box


If IsLoaded("ParentFormName") Then
Set Ctl = Forms!ParentFormName!txtDateClosed
DoCmd.SelectObject acForm, "ParentFormName"
Ctl = Me.txtCloseDate (The control on the Child Form)
End If
 
W

Wayne Morgan

The code you have could be simplified to

If IsLoaded("ParentFormName") Then
Forms!ParentFormName!txtDateClosed = Me.txtCloseDate
End If

However, I assume that the child form is storing all of the extra data
you're entering in its own table. Is it also storing this date? If so, is it
also storing a unique ID value so that the record in the child form's table
can be linked to the record in the main form's table? If so, then you don't
need this date in the main form's table, you can do a DLookup() to fill in
the date textbox on the main form. This will make this control a "calculated
control". After the record has been saved in the child form, requery the
textbox on the main form. If you are opening the child form using the
acDialog window mode argument, you can do this in the line immediately
following the OpenForm line.

Me.txtDateClosed.Requery

The Control Source for this textbox on the main form would be:

=DLookup("DateClosedFieldName", "ChildFormsTableName", "UniqueIDField = " &
[txtUniqueID])
 
T

Tru

Wayne, Your beautiful maaan! Thanx Partner. Also you are right about my
structure and I was using the DLookup Method but the problem was the we have
several close dates in the Child Table because that table is a History Table
for our cases. I thought it would be less complicated and faster this way.
--
Thanx!


Wayne Morgan said:
The code you have could be simplified to

If IsLoaded("ParentFormName") Then
Forms!ParentFormName!txtDateClosed = Me.txtCloseDate
End If

However, I assume that the child form is storing all of the extra data
you're entering in its own table. Is it also storing this date? If so, is it
also storing a unique ID value so that the record in the child form's table
can be linked to the record in the main form's table? If so, then you don't
need this date in the main form's table, you can do a DLookup() to fill in
the date textbox on the main form. This will make this control a "calculated
control". After the record has been saved in the child form, requery the
textbox on the main form. If you are opening the child form using the
acDialog window mode argument, you can do this in the line immediately
following the OpenForm line.

Me.txtDateClosed.Requery

The Control Source for this textbox on the main form would be:

=DLookup("DateClosedFieldName", "ChildFormsTableName", "UniqueIDField = " &
[txtUniqueID])

--
Wayne Morgan
MS Access MVP


Tru said:
Scenario: My Main Form (Parent Form) has a bound text control on it called
txtDateClosed that the user is not permitted to access. The only way this
field can be completed if they Click a command button on the Parent Form
to
open the other form (Child Form) and complete the required information on
the
Child Form. Once the required information is completed which includes the
date information for txtDateClose on the Parent Form. I am trying to
transfer
the txtCloseDate on the Child Form to the txtDateClosed on the Parent Form
but nothing is happening, I'm not getting no error messages either, below
is
the code I am using:

Dim Ctl As Control

'If Parent Form is loaded, select it, and set value
'of selected text box


If IsLoaded("ParentFormName") Then
Set Ctl = Forms!ParentFormName!txtDateClosed
DoCmd.SelectObject acForm, "ParentFormName"
Ctl = Me.txtCloseDate (The control on the Child Form)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top