Results 1 to 12 of 12
  1. #1
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155

    Regarding forms

    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?

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Is the field displayed on the subform row? Just click on it.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,673
    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.

  4. #4
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155

    Regarding Forms

    Quote Originally Posted by ArviLaanemets View Post
    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.

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    txtStartdate is a field on the subform datasheet
    txtTarget is a textbox on the main form.
    This code goes behind the subform.

    Code:
    Private Sub txtStartDate_Click()
        Me.Parent.txtTarget = txtStartDate
    End Sub
    Code will copy contents of txtStartDate on the subform datasheet to the textbox txtTarget on the main form.

  6. #6
    Join Date
    Apr 2017
    Posts
    1,673
    Quote Originally Posted by Kundan View Post
    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.
    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.

  7. #7
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by davegri View Post
    txtStartdate is a field on the subform datasheet
    txtTarget is a textbox on the main form.
    This code goes behind the subform.

    Code:
    Private Sub txtStartDate_Click()
        Me.Parent.txtTarget = txtStartDate
    End Sub
    Code will copy contents of txtStartDate on the subform datasheet to the textbox txtTarget on the main form.
    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.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Now when I select a record in the datasheet subform all its fields should be entered in the respective fields on the main form.
    So do it this way with all code behind subform:

    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
    Now, make it so that ANY field clicked in the subform row will call the above code...

    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

  9. #9
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155

    Regarding Forms

    Quote Originally Posted by davegri View Post
    So do it this way with all code behind subform:

    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
    Now, make it so that ANY field clicked in the subform row will call the above code...

    Code:
    Private Sub txtAnother_Click()
        Call txtStartDate_Click
    End Sub
    
    Private Sub txtYetAgain_Click()
        Call txtStartDate_Click
    End Sub
    'And so on...
    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?

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Rearrange it this way:
    Create a new 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
    Then have all the on-click events call that sub.

  11. #11
    Kundan is offline Competent Performer
    Windows XP Access 2013 32bit
    Join Date
    Mar 2018
    Posts
    155
    Quote Originally Posted by davegri View Post
    Rearrange it this way:
    Create a new 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
    Then have all the on-click events call that sub.
    Thank You!!! It’s working wonderfully! God bless you!

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,824
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 11-06-2017, 01:23 PM
  2. Replies: 2
    Last Post: 04-05-2016, 08:29 AM
  3. Replies: 3
    Last Post: 03-23-2016, 12:45 PM
  4. Replies: 2
    Last Post: 11-05-2014, 09:16 AM
  5. Replies: 1
    Last Post: 01-04-2011, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums