Results 1 to 6 of 6
  1. #1
    tbassngal is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    27

    Question Assign Combo Box from Main form to Subform

    I have a main form frmAddDoc with a field txtTitle and a subform subfrmReference that loads from the main with an on_click event button. I have a field txtTitle in the subform that should be assigned the value txtTitle from the main when the form is loaded from the on_click event of the main. Can someone please provide to me an example of code that would do this? I haven't done it in such a long time and my syntax is just not working.

    Bottom line: I want subtxtTitle in the subform to equal the value of txtTitle from the main form.

    Me!subfrmReferences.Form!subtxtTitle = Forms![frmAddNewDoc]![txtTitle].Value



    ????

    Anyone anyone?
    Last edited by tbassngal; 07-14-2011 at 01:34 PM. Reason: No responses from anyone!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    What do you mean by 'loads from the main with an on_click event button'? A subform would load WITH the main form. Is the subform txtTitle an unbround control? If so, can reference the main form txtTitle in the ControlSource with Forms![frmAddNewDoc]![txtTitle]. If not, what event is the code in? Are the the textbox names same as the field names? Looks like you have it behind the subform, so try:
    Me.subtxtTitle = Forms![frmAddNewDoc]![txtTitle]
    or
    Me.subtxtTitle = Form_frmAddNewDoc!txtTitle

    If you use dot, as in Me. or Form_frmAddNewDoc. then intellisense popups will be provoked. I use the ! when referencing field name of RecordSource.
    Last edited by June7; 07-18-2011 at 11:57 AM.
    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.

  3. #3
    tbassngal is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    27
    Maybe the post was confusing... sorry. The frmAddDoc is unbound as are its controls. The subfrmReferences is also unbound as are it's controls. I do not want the subform to be visible unless someone clicks a button titled "Add Document References" (cmdOpenRefSub). When they click the button, the subform should be visible, and it should GetFocus, the control subtxtTitle should have the same value as entered into the control txtTitle main form frmAddDoc. Since the forms are both unbound, they don't have any master fields linked... because you can't link them through the properties with unbound forms.

    Still no luck... when I assign the control subtxtTitle control source as Forms![frmAddNewDoc]![txtTitle] - I get the error #Name? in the subtxtTitle text box.

    Private Sub Form_Load()
    With Me![subfrmReferences].Form
    .Visible = False
    End With
    End Sub

    Private Sub cmdAddNew_Click()
    Dim MyDB As Database, rcsDocControl As Recordset
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    Set rcsDocControl = MyDB.OpenRecordset("tblDocControl")

    If Nz([txtDoc_ID], "") = "" Or Nz([txtTitle], "") = "" Or Nz([txtRevision], "") = "" Or Nz([txtDate_Added_DB], "") = "" _
    Or Nz([cboType], "") = "" Or Nz([cboOwner], "") = "" Or Nz([URL_Location], "") = "" Then
    MsgBox "You must complete all fields!", vbCritical, "Incomplete Record!"
    Exit Sub
    End If

    rcsDocControl.AddNew
    rcsDocControl![Doc_ID] = Forms![frmAddNewDoc]![txtDoc_ID]
    rcsDocControl![Title] = Forms![frmAddNewDoc]![txtTitle]
    rcsDocControl![Revision] = Forms![frmAddNewDoc]![txtRevision]
    rcsDocControl![Date_Added_DB] = Forms![frmAddNewDoc]![txtDate_Added_DB]
    rcsDocControl![Type] = Forms![frmAddNewDoc]![cboType]
    rcsDocControl![Owner] = Forms![frmAddNewDoc]![cboOwner]
    rcsDocControl![Location] = Forms![frmAddNewDoc]![URL_Location]
    rcsDocControl.Update

    MsgBox "The Document has been Added!", vbDefaultButton1, "Document Added!"

    txtDoc_ID = ""
    txtTitle = ""
    txtRevision = ""
    txtDate_Added_DB = ""
    cboType = ""
    cboOwner = ""
    URL_Location = ""

    Exit Sub
    End Sub

    Private Sub cmdOpenRefSub_Click()
    '[syntax of subform control] = Me.txtTitle
    Me.[subtxtTitle] = [Forms]![frmAddNewDoc]![txtTitle]
    End Sub
    Last edited by tbassngal; 07-18-2011 at 07:50 AM. Reason: Added Code

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Why are you working with unbound forms?

    Is the visibility code working? If not, instead of referring to subform for visibility, refer to the container control that holds the subform. I always give container a name different from the form it holds, like ctrReference. So Me.ctrReference.Visible = False

    In VBA I refer to controls with this syntax:
    Me.controlname
    Form_formname.controlname

    The dot provokes intellisense popup tips and control names will be listed. I use the ! when referencing fields of recordset or form's RecordSource, like Me![URL_Location]


    cmdOpenRefSub doesn't show code to make subform visible nor to give it focus.

    The #Name? error means code is not finding the reference. I presume cmdOpenRefSub is on main form. Reference syntax is wrong. Try:
    Me.ctrReference.Form.subtxtTitle = Me.txtTitle
    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.

  5. #5
    tbassngal is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    27
    I am working with unbound forms because it gives me more flexibility... I have always done this. I haven't done any programming in quite a long time and I obviously don't keep up on the new ways to write VBA code unfortunately. To answer your question, yes, the code that establishes whether the subform is visible or not is working without any problems. Can you please tell me what you mean by container control? I always name all my fields and forms with different names so that shouldn't be an issue.

    I make the form not visible in the form load event of frmAddDoc. I would have made in not visible on subfrmReferences with the click of another button. You are correct, I do not have the GotFocus coded here because I couldn't get it to work.

    Maybe I am going about this all wrong... I don't know. Maybe I need to start using bound forms. I am having a hard time understanding what you are talking about where the container is concerned.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    A subform/subreport is established by installing a container on the main object. When you select the Subform/Subreport icon from the control designer you are selecting a container control. The container control SourceObject property identifies the associated form or report by name. Select the container frame to view its properties. Click into the container to select the associated form or controls on the form.

    Not using bound forms just means more programming work. I like programming, but not that much. I have all the flexibility I want even with bound forms/controls.
    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. Subform Combobox based on Main form combo box
    By accessmom in forum Forms
    Replies: 5
    Last Post: 02-21-2011, 07:02 AM
  2. Subform in a Tab Control on a Main form
    By jpkeller55 in forum Access
    Replies: 4
    Last Post: 01-08-2011, 12:31 PM
  3. Replies: 5
    Last Post: 01-02-2011, 10:09 AM
  4. Replies: 6
    Last Post: 06-03-2009, 02:01 PM
  5. Replies: 0
    Last Post: 08-17-2008, 12:19 PM

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