Carry forward a fields value

  • Thread starter Thread starter Stephen Lynch
  • Start date Start date
S

Stephen Lynch

I have a grid on form 1. I have detail records for the same table on form 2.

I want to doubleclick the row on Form 1 and carry forward the ssnumber to
Form 2, populate the combo box, refresh the combo to select the employee
that i clicked on in form 1.

Here's what I have done:

Added on the doubleclick method of the field in grid.

DoCmd.openform.form1


On the onload event of form2,

I put

[combobox1] =
Forms![EmployeeMain]![EmployeesDetail]![Social Security]


It seems like it is carring the value, but the combo is not refreshing.
Questions:

1. Is there a command to issue a click to the combo. I think I an populating
it with the value but now I need to click it.

2. Can I put this code on the selected row to open Form 2 and carry the
value of the field SSNumber?
 
I would stay away from OnLoad and just make the DefaultValue of combobox1 on
Form 2 this:

=Forms![EmployeeMain]![EmployeesDetail]![Social Security]

This will immediately show the value when the form opens. I think this will
provide a solution for both your questions.
 
I have a similar problem, but the secondary form [frmInvoice] could be
called from a couple different forms [frmaltPOs], [frmNewPOs], etc. I read
elsewhere that I could use this code in the BeforeEvent property.

Private Sub Form_BeforeInsert(Cancel As Integer)

With Forms![frmPurchaseOrder]
If Not IsNull([Forms]![frmPurchaseOrder]![PO#]) Then
Me.POID = [Forms]![frmPurchaseOrder]![PO#]
End If
End With

End Sub


How do I allow the [POID] field to get a value from whichever previous form
[frmInvoice] is called from , such as [Forms]![frmaltPOs]![PO#]? Is there a
PreviousObjectName method?


malick
 
There is not, to my knowledge a PreviousObject property, however, here's a
possible workaround:

At the time that Form_Load executes, Screen.ActiveForm still points to the
previous form.
So you can save that to a variable scoped to frmInvoice's module.
OUTSIDE the event procedure, declare:
Private LastFrm as Form
The INSIDE the Form_Load procedure, add this code:
Set LastFrm=Screen.ActiveForm
Now, wherever you have this in your code:
[Forms]![frmPurchaseOrder]
substitute this:
LastFrm

Another possible approach would be to pass the value of [PO#] into
frmInvoice in the OpenArgs argument.


malick said:
I have a similar problem, but the secondary form [frmInvoice] could be
called from a couple different forms [frmaltPOs], [frmNewPOs], etc. I read
elsewhere that I could use this code in the BeforeEvent property.

Private Sub Form_BeforeInsert(Cancel As Integer)

With Forms![frmPurchaseOrder]
If Not IsNull([Forms]![frmPurchaseOrder]![PO#]) Then
Me.POID = [Forms]![frmPurchaseOrder]![PO#]
End If
End With

End Sub


How do I allow the [POID] field to get a value from whichever previous form
[frmInvoice] is called from , such as [Forms]![frmaltPOs]![PO#]? Is there a
PreviousObjectName method?


malick


Brian said:
I would stay away from OnLoad and just make the DefaultValue of combobox1 on
Form 2 this:

=Forms![EmployeeMain]![EmployeesDetail]![Social Security]

This will immediately show the value when the form opens. I think this will
provide a solution for both your questions.
 
The approach I have used in the past when opening a form from multiple
locations is to pass the desired value to a global variable in the VBA code
just before opening the form (this needs to be done on each form that would
contain that value and be used to open the new form). Then, in Form_Open of
the form being opened, set the default value of the combo box to the global
variable. You could easily transfer this into VBA setting the value (not the
default value) of the combo box in Before Insert instead of Form_Open.

This may be less efficient than methods in the other post, though. I just
haven't experimented with other methods.

malick said:
I have a similar problem, but the secondary form [frmInvoice] could be
called from a couple different forms [frmaltPOs], [frmNewPOs], etc. I read
elsewhere that I could use this code in the BeforeEvent property.

Private Sub Form_BeforeInsert(Cancel As Integer)

With Forms![frmPurchaseOrder]
If Not IsNull([Forms]![frmPurchaseOrder]![PO#]) Then
Me.POID = [Forms]![frmPurchaseOrder]![PO#]
End If
End With

End Sub


How do I allow the [POID] field to get a value from whichever previous form
[frmInvoice] is called from , such as [Forms]![frmaltPOs]![PO#]? Is there a
PreviousObjectName method?


malick


Brian said:
I would stay away from OnLoad and just make the DefaultValue of combobox1 on
Form 2 this:

=Forms![EmployeeMain]![EmployeesDetail]![Social Security]

This will immediately show the value when the form opens. I think this will
provide a solution for both your questions.
 
Back
Top