How to fill new records with data from previous screen.

C

Capt Jim Cook

Please help. I can't remember how I did this last time (a long time ago).
I have a simple main menu with a combo box that allows users to select their
employee ID# (from a table). It then displays their name in a text field and
determines what control buttons are enabled based on data in the employee ID
table. One of the options is to request supplies.

I have a DATA ENTRY screen for requesting supplies. The 1st field is the
employee number. I want to fill this field (and the underlying table's data
element) from the selection on the previous menu screen.

I can display their name on the second screen by setting the default value
to [Forms]![MainMenu]![txtName] if I leave the control source empty but if I
try to specify a default value and a control source (table field) I get an
error. When I try to set the default value of a text box on the second
screen to the cmbEmpID combo box (ie =[Forms]![MainMenu]![cmbEmpID]) , it is
just blank.

I want to simply add new supply requests and store the employee # so we know
who placed the request.

Thanks,
Jim
 
C

Capt Jim Cook

OK, I now have a text box in the second screen displaying the selected
contents of the first screens combo box. However, it still won't save the
value in the table, even though every other field on the screen is saved. ( I
double checked that I set the Contro Source to the table data element. The
Employee ID is not an indexed field in the supply request table.

Any thoughts? Thanks,
Jim
 
J

John Vinson

I have a DATA ENTRY screen for requesting supplies. The 1st field is the
employee number. I want to fill this field (and the underlying table's data
element) from the selection on the previous menu screen.

I can display their name on the second screen by setting the default value
to [Forms]![MainMenu]![txtName] if I leave the control source empty but if I
try to specify a default value and a control source (table field) I get an
error. When I try to set the default value of a text box on the second
screen to the cmbEmpID combo box (ie =[Forms]![MainMenu]![cmbEmpID]) , it is
just blank.

I want to simply add new supply requests and store the employee # so we know
who placed the request.

By far the simplest way to do this would be to make the data entry
Form (to use the proper name, rather than "screen") a Subform of the
MainMenu form.

If that's not practical, then pass the employee ID's value in the
OpenArgs argument of the OpenForm method, and use the data entry
form's Open event to set the DefaultValue property of the EmpID
control. Something like

DoCmd.OpenForm strDocument, WhereCondition := strCriteria, _
OpenArgs := Me.cmbEmpID

and in the form's Open event code like

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' Was an OpenArgs passed?
Me.txtEmpID.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End If
End Sub


John W. Vinson[MVP]
 

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