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

Transfer information from subform to 3 different fields in a form

Status
Not open for further replies.

andreas charalambous

Technical User
Oct 18, 2016
1
CY
I have a subform in a form which always displays three records.
what i need to do is when a click on a button to transfer these data to three fields in my form.

subform name: subform1
main form : itemsales
fields to update on main form: text1,text2,text3

(text1 should get first record in the subform, text2 should get the second and text3 should get the third one).

what vba code should i use to do that?
thanks
 
Values in a form are typically stored in a table. Use DLookup() or other method to display the values on your main form. If you think you need to store the three values in more than one table then it may require some code to lookup and set the values in the main form.

Duane
Hook'D on Access
MS Access MVP
 
Assuming you wanted to move the first three records from a subform to controls on the main form
Code:
Private Sub Command28_Click()
  'code on main form
  'subform control called SubFrmControl
  'field is called 'data'
  Dim rs As DAO.Recordset
  Set rs = Me.subFrmControl.Form.RecordsetClone
  rs.MoveFirst
  If rs.recordCount = 3 Then
    Me.Text1 = rs.Fields("data")
    rs.MoveNext
    Me.Text2 = rs.Fields("data")
    rs.MoveNext
    Me.Text3 = rs.Fields("data")
  Else
    MsgBox "There are not three records"
  End If
 End Sub

What is the big picture on what you are trying to accomplish? There may be a cleaner approach. Does not make much sense to me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top