Results 1 to 9 of 9
  1. #1
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32

    Having problem to get the recordset when double clicked on a list box

    I have problems with a list box for getting recordset on a subform.

    my code is


    Code:
    Me.Recordset.FindFirst "[ID]=" & Me.ListBox
    where Bound column of the ListBox is the ID.

    It just does not seem to be working at all.

    Please help. Thank you in advance.

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Me.Recordset refers to the Main form and not the SubForm.
    Try this assuming ID is a field in the subform.
    Code:
    Me.SubFormControlName.Form.Recordset.FindFirst "[ID]=" & Me.ListBox

  3. #3
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32
    Quote Originally Posted by amrut View Post
    Me.Recordset refers to the Main form and not the SubForm.
    Try this assuming ID is a field in the subform.
    Code:
    Me.SubFormControlName.Form.Recordset.FindFirst "[ID]=" & Me.ListBox
    Thank you for your reply.

    But it come up with a compile error: Method or data member not found.

    It used to work before, but it suddenly does not work anymore. So I am wondering if my other code interrupted this code.

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Have you replaced the "sub form control name" with your one ??

  5. #5
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32
    Quote Originally Posted by amrut View Post
    Have you replaced the "sub form control name" with your one ??
    Yes I did, and it had more error than before. My the list box is in my subform, so i should use me.subform instead?

  6. #6
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32
    I might be having problems with the record selector. It only show one record in the subform. The subform.SourceObject is controlled by the mainform with vba.

    my code in the mainform is
    Code:
    Me.Subform.SourceObject = Me.SubCategoryName.Value
    Still, the subform record search is not working.

  7. #7
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32
    I think I have got the problem, now I need a solution. My subform is linked with more than one field by default!!! How can I set the link in vba?

  8. #8
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Source object for subform cannot be a value, it should be a form. To refer to a control on subform, You have to use the syntax Me.SubformControlName.Form.ControlName. Read more here http://access.mvps.org/access/forms/frm0031.htm
    My subform is linked with more than one field by default!!!
    Cannot follow this. Source object can be set using the code
    Code:
    Me.Subform.SourceObject = "Form.Name of Form"
    Never used VBA to set the Master and Child fields.

  9. #9
    Jo.. is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2015
    Posts
    32
    Quote Originally Posted by amrut View Post
    Source object for subform cannot be a value, it should be a form. To refer to a control on subform, You have to use the syntax Me.SubformControlName.Form.ControlName. Read more here http://access.mvps.org/access/forms/frm0031.htm

    Cannot follow this. Source object can be set using the code
    Code:
    Me.Subform.SourceObject = "Form.Name of Form"
    Never used VBA to set the Master and Child fields.
    me.subform.sourceonject= me.textbox.value

    The code is right. I got the solution for this one.

    The relationship between the main form and subform has more than one link, thats why. After I remove the other link other than the projectid (my key to main form and subform). It is working perfectly.

    Thank you so much for your help. This thread is solved.

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

Similar Threads

  1. Double loop recordset
    By silverspr in forum Programming
    Replies: 7
    Last Post: 03-07-2012, 01:43 PM
  2. Replies: 0
    Last Post: 12-06-2011, 11:01 AM
  3. double update query problem
    By tss in forum Queries
    Replies: 9
    Last Post: 11-04-2011, 08:50 AM
  4. Replies: 1
    Last Post: 11-09-2010, 03:02 PM
  5. Replies: 6
    Last Post: 04-23-2010, 06:43 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