A
Anthony Dowd
Hi
I have two forms "Form 1" and "Form 2". "Form 2" opens by clicking on a
command button on "Form 1".
I successfully used the following code in the Load event of "Form 2" to
create default values that are automatically entered into a field on "Form
2" called "Field2" depending on the value selected in a combo box called
"Field1" on "Form 1". The value in "Field1" is itself automatically inserted
depending on the value inserted into another field on "Form 1" called
"FieldA".
My database is set up so that when the user selects a value in "FieldA" on
"Form 1", the value in "Field1" updates automatically and a message box
appears telling the user they must enter information in another form. The
user clicks on ok and the form opens. The form is closed after the data are
entered and the user is taken back to "Form1". The user then clicks on the
command button to open "Form 2".
********************start code******************
Var1 = DLookup("[Field1]", "Table1", "[ID]=" & Me!ID)
Var2 = DLookup("[Field2]", "Table2", "[ID]=" & Me!ID)
If (IsNull(Var2)) Then
If (Var1 = "Selected Value in Combo Box") Then
Forms![Form2]![Field2] = "Default value in Field2 on Form 2"
Else
etc...
End If
End If
*****************end code*************************
This code inserts the correct value into "Field2" when I open "Form 2" and I
can edit this value if required and the new value will 'stick'. However, if
I go back to "Form 1" and change the value of "FieldA" so that "Field1" also
changes, I find the old value in "Field2" when I open "Form2" again. I have
tried inserting similar code into the change event of "Form2", but this then
prevents the user from amending the data in "Field2". Any suggestions?
Thanks
Anthony
I have two forms "Form 1" and "Form 2". "Form 2" opens by clicking on a
command button on "Form 1".
I successfully used the following code in the Load event of "Form 2" to
create default values that are automatically entered into a field on "Form
2" called "Field2" depending on the value selected in a combo box called
"Field1" on "Form 1". The value in "Field1" is itself automatically inserted
depending on the value inserted into another field on "Form 1" called
"FieldA".
My database is set up so that when the user selects a value in "FieldA" on
"Form 1", the value in "Field1" updates automatically and a message box
appears telling the user they must enter information in another form. The
user clicks on ok and the form opens. The form is closed after the data are
entered and the user is taken back to "Form1". The user then clicks on the
command button to open "Form 2".
********************start code******************
Var1 = DLookup("[Field1]", "Table1", "[ID]=" & Me!ID)
Var2 = DLookup("[Field2]", "Table2", "[ID]=" & Me!ID)
If (IsNull(Var2)) Then
If (Var1 = "Selected Value in Combo Box") Then
Forms![Form2]![Field2] = "Default value in Field2 on Form 2"
Else
etc...
End If
End If
*****************end code*************************
This code inserts the correct value into "Field2" when I open "Form 2" and I
can edit this value if required and the new value will 'stick'. However, if
I go back to "Form 1" and change the value of "FieldA" so that "Field1" also
changes, I find the old value in "Field2" when I open "Form2" again. I have
tried inserting similar code into the change event of "Form2", but this then
prevents the user from amending the data in "Field2". Any suggestions?
Thanks
Anthony