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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form auto populate existing data based on ID

Status
Not open for further replies.

abbottboi

IS-IT--Management
Nov 14, 2005
94
CA
Hi,

I have a form that updates an existing table.

The problem is when i would like to create a new record based on a existing ID i would like the first_name and last_name field to auto-populate based on when i select the user_id in the pull down menu.

So, when i select ID '1' i would like it to auto-populate first_name and last_name field based on existing info in the user table.

any ideas?

thanks again
 
Place VBA code that will execute when you click a button to add a new record for the currently displayed person.

(assumptions: txtFirst_Name and txtLast_Name are the controls on the form that contain those fields you want to use in the new record, and the name of the table is MyData.)


Dim strSQL as string

strSQL = "INSERT INTO MyData (First_Name, Last_Name) select '" & me.txtFirst_Name & "' as First_Name, '" & me.txtLast_Name & "' as Last_Name FROM MyData;"

docmd.RunSQL strSQL


That (or similar code, I didn't check this code) should do what you want.

Bob
 
I had a similar one, but I copied all fields by stepoping though the fields in a recordset:

Copy all the field datea to an array, and then send the array to the new record:

Code:
ReDim arFieldCopies(0 To rst.Fields.Count - 1)
'fill field data array
For Each fld In rst.Fields
    arFieldCopies(a) = fld.Value
    a = a + 1
    End If
Next fld

rst.AddNew 'now add same fields in same order
'initialise variables
a = 0
For Each fld In rst.Fields
    fld.Value = arFieldCopies(a)
    a = a + 1
    End If
Next fld
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top