When I select a record in a subform, how do I access a particular field of that record? Is there any function or method for it?
When I select a record in a subform, how do I access a particular field of that record? Is there any function or method for it?
Is the field displayed on the subform row? Just click on it.
Setting TabIndex property of control determines order of control on form. When you activate a new row in continuous form, a visible and enabled control with lowest TabIndex will be activated. When TabStop property of form is True, Pressing Tab key activates next visible and enabled control with next TabIndex, etc. You can activate any control clicking on it.
The subform displays data in the form of a data sheet. When I select a record in it I want to copy the value of a particular field of the selected record to be copied to a control on the main form. I want to know how do I access the value of the particular field of the selected record of the subform.Setting TabIndex property of control determines order of control on form. When you activate a new row in continuous form, a visible and enabled control with lowest TabIndex will be activated. When TabStop property of form is True, Pressing Tab key activates next visible and enabled control with next TabIndex, etc. You can activate any control clicking on it.
txtStartdate is a field on the subform datasheet
txtTarget is a textbox on the main form.
This code goes behind the subform.
Code will copy contents of txtStartDate on the subform datasheet to the textbox txtTarget on the main form.Code:Private Sub txtStartDate_Click() Me.Parent.txtTarget = txtStartDate End Sub
So the subform serves as record selector, and actual editing is done in Main form? Probably the Main form is unbound one - you read record data in, edit, and then save control's values into table? Why not have the Main form as single form linked to table, with controls for all fields user has to edit, and a combo/list box to select record? Much simpler to build up, and works faster. When you want to prevent user accidently changing something, then you can disable editing for selected record whenever another record is selected (except for new record), and have a button on form to toggle enabling/disabling record editing.
Btw, you did write 'data sheet'? Are you really using the subform designed as Data Sheet, not a continuous form? I myself have never find a reason to use Data Sheet forms.
Thank You! The code works well for individual fields. Now when I select a record in the datasheet subform all its fields should be entered in the respective fields on the main form.txtStartdate is a field on the subform datasheet
txtTarget is a textbox on the main form.
This code goes behind the subform.
Code will copy contents of txtStartDate on the subform datasheet to the textbox txtTarget on the main form.Code:Private Sub txtStartDate_Click() Me.Parent.txtTarget = txtStartDate End Sub
So do it this way with all code behind subform:Now when I select a record in the datasheet subform all its fields should be entered in the respective fields on the main form.
Now, make it so that ANY field clicked in the subform row will call the above code...Code:Private Sub txtStartDate_Click() 'move ALL the fields from the subform to the main form. Me.Parent.txtTarget = txtStartDate Me.Parent.txtAnother = txtAnother Me.Parent.txtYetAgain = txtYetAgain . . . End Sub
Code:Private Sub txtAnother_Click() Call txtStartDate_Click End Sub Private Sub txtYetAgain_Click() Call txtStartDate_Click End Sub 'And so on...
Last edited by davegri; 04-20-2018 at 12:03 AM. Reason: sp
When I Call the subroutine from other controls an error comes "Arguments not optional". While calling I have not given any arguments. The original subroutine has the parameter "Cancel As Integer". What argument should I give while calling?So do it this way with all code behind subform:
Now, make it so that ANY field clicked in the subform row will call the above code...Code:Private Sub txtStartDate_Click() 'move ALL the fields from the subform to the main form. Me.Parent.txtTarget = txtStartDate Me.Parent.txtAnother = txtAnother Me.Parent.txtYetAgain = txtYetAgain . . . End Sub
Code:Private Sub txtAnother_Click() Call txtStartDate_Click End Sub Private Sub txtYetAgain_Click() Call txtStartDate_Click End Sub 'And so on...
Rearrange it this way:
Create a new sub:
Then have all the on-click events call that sub.Code:Private sub MoveToMain() 'move ALL the fields from the subform to the main form. Me.Parent.txtTarget = txtStartDate Me.Parent.txtAnother = txtAnother Me.Parent.txtYetAgain = txtYetAgain . . . End Sub
Thank You!!! It’s working wonderfully! God bless you!Rearrange it this way:
Create a new sub:
Then have all the on-click events call that sub.Code:Private sub MoveToMain() 'move ALL the fields from the subform to the main form. Me.Parent.txtTarget = txtStartDate Me.Parent.txtAnother = txtAnother Me.Parent.txtYetAgain = txtYetAgain . . . End Sub
Sounds like emulating split form. I don't usually like split form but i have used it once. Have you looked at?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.