Results 1 to 12 of 12
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    242

    Print a record on a subform

    Hi to all,

    I have a main form (frmMembersInfo) with a combo box. The user selects a name from the combo box and data is shown on the subform (frmMembersInfoSubForm), The control name of the subform is (cntMembersInfoSubForm).
    On the main form I have a button to print the data on the subform for the selected person.

    below is the code:


    Code:
    If Len(Me.[frmMembersInfoSubForm].txtFirstName & "") = 0 Or Len(Me.[frmMembersInfoSubForm].txtFamilyName & "") = 0 Then
             MsgBox "Please select a member, " & vbCrLf _
                    & "before attempting to preview the report." & vbCrLf _
                    & vbInformation, "Personal Information Needed..."
    
            Exit Sub
        Else
            If Me.Dirty = True Then  'Save the record
               Me.Dirty = False
            End If
    
            DoCmd.OpenReport "rptMemberReportInfo", view:=acViewPreview, _
                  WhereCondition:="[pkMemberId] = " & Me.[frmMembersInfoSubForm].pkMemberId 
        End If

    The If Len(Me.... has an error. I am not able to find it out. Any help is appreciated

    Khalil

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The If Len(Me.... has an error. I am not able to find it out. Any help is appreciated
    What error message or error number do you get
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    If Len(Me.[frmMembersInfoSubForm].txtFirstName) = 0 Or Len(Me.[frmMembersInfoSubForm].txtFamilyName) = 0 Then
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    242
    Hi,

    Did not work.
    Here is the error message I have:
    Error 2465: can't find the field '|1' refered to in your expression

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Do you get that message with your code or mine.
    Have you spelt the names of the text boxes correctly.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I didn't read your OP as carefully as I might have.
    Try:
    If Len(Me.[cntMembersInfoSubForm].txtFirstName) = 0 Or Len(Me.[cntMembersInfoSubForm].txtFamilyName) = 0 Then
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    242
    I tried your code and got the following:

    Compile error: Method or data member not found

    with yellow highlight on txtFirstName

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    That suggests to me, that there is no control on the subform with that name.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Len(Me.cntMembersInfoSubForm.Form.txtFirstName) = 0 Or Len(Me.cntMembersInfoSubForm.Form.txtFamilyName) = 0 ?

    Here's how I troubleshoot hierarchies like this:
    In the immediate window drill down and test a property of the objects as you go. Probably every object has a name, so
    ?Me.Name << should give you the name of the active form
    ?Me.cntMembersInfoSubForm.Name << according to what I read in the posts, should return cntMembersInfoSubForm. Never mind that it tells you what you already know; it tells you you're on the right track.
    ?Me.cntMembersInfoSubForm.txtFamilyName << should fail because the textbox is not the next object in the hierarchy - the FORM on the subform would be next?
    ?Me.cntMembersInfoSubForm.Form.Name should return the name of the subform in the subform container.
    and so on...

    Last edited by Micron; 02-11-2021 at 04:48 AM. Reason: code correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    242
    Hi,

    I tried this in the immediate window:

    ?Me.Name
    frmMembersInfo_New

    ?Me.cntMembersInfoSubForm.Name
    cntMembersInfoSubForm

    ?Me.cntMembersInfoSubForm.txtFirstName
    ERROR: Method or data member not found.

    I think it is not finding the control on the subform.

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Did you not try:
    Me.cntMembersInfoSubForm.Form.txtFirstName
    As Micron suggested in post #9
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    242
    This worked for me:

    Me.cntMembersInfoSubForm!txtFamilyName

    Thanks to All

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

Similar Threads

  1. Replies: 5
    Last Post: 07-29-2014, 01:05 PM
  2. Replies: 8
    Last Post: 08-09-2013, 09:52 AM
  3. Replies: 1
    Last Post: 12-03-2012, 03:15 PM
  4. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  5. Replies: 5
    Last Post: 10-26-2011, 02:59 PM

Tags for this Thread

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