Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add and add new

Status
Not open for further replies.

ralphus

Technical User
Dec 30, 2004
28
0
0
GB
when a user wishes to create a new record it is sometimes helpfull for some items from the record their viewing to be autopopulated into the new record how is this possible?
 
Easiest way is to create default values on those form fields (Design View - Properties)... you can also do this on the underlying table.

Alternative method for more complex pre-populating is to use the form's OnCurrent event and check if the record displayed is a new record, then perform code, e.g.
Code:
Private Sub Form_Current()
    If Me.NewRecord Then
        'Code to populate here
    End If
End Sub


[pc2]
 
I'd use a new form that you'd load the data into, the form would be a Data Entry form so that it always opens to a new record, then I'd open this new form while the calling form is still open. I'd create a function that would set the values that I want and I'd call this function during the form's On Load Event as in this example that loads data from the calling form (frmEmps) and a subform (frmSubEmps) on the calling form.

Private Sub Form_Load()
Call fLoadValues
End Sub

Function fLoadValues()
If Me.NewRecord Then
Me.txtID = forms!frmEmps.txtEmployeeID
Me.txtName = forms!frmEmps.txtFirstName & " " & forms!frmEmps.txtLastName
Me.txtTitle = forms!frmEmps.Form!frmSubEmps!txtTitle
Me.txtDateHired = forms!frmEmps.Form!frmSubEmps!txtHireDate
Me.txtDateOfBirth = forms!frmEmps.Form!frmSubEmps!txtBirthDate
End If
End Function

PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top