Results 1 to 14 of 14
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Subforms won't cooperate

    I have two subform that interact. The first one searches a table for using one or two strings to filter a list. This list is then display in a combo box for the user to pick the correct diagnosis which populates the code and description combo boxes. Once the user is happy with the selection, they click they click the select code button which populates another subform which is a continuous form displaying many records. As long as the focus is on the new/blank record this works perfectly, but if the focus is on an earlier record, that record is replaced with the new code and description. I want to make sure this one happens on the new blank record, but I can get the gotoRecord acNew command to work. I've tried this 10 different ways, so I'll only show you a few.



    Code:
      Form_Clinical_Summary_ICD10.txtFromDate.SetFocus
                DoCmd.GoToRecord acDataForm, Form_Clinical_Summary_ICD10, acNewRec
                Form_Clinical_Summary_ICD10.cbo_ICD10 = Form_frmLookup_ICD10.cboICD10
                Form_Clinical_Summary_ICD10.cboICD10_Description = Form_frmLookup_ICD10.cboICD10.Column(1)
    This fails on line 2. with this message.
    Click image for larger version. 

Name:	mvb2.JPG 
Views:	32 
Size:	20.2 KB 
ID:	26918

    So I tried it in quotes, with and without the Form_ prefix and get this.
    Click image for larger version. 

Name:	mvb3.JPG 
Views:	32 
Size:	18.5 KB 
ID:	26919

    I'm going round in circles and periodically crashing my program.

    Any ideas or questions?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You should *not* be using that particular syntax in your code but go through the Forms collection: http://access.mvps.org/access/forms/frm0031.htm

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    RG, I appreciate the answer and I've tried to do this in any number of iterations without success. I don't normally do this, but if you can solve what I see is a small problem, I would greatly appreciate it. The two forms in question are both subforms of a larger form. The code copies the data from one subform to another. Before that happens I want to put the focus on the new record just in case the user has been touring around on some older records. These two lines, even in their bad syntax run perfectly well. I know this is essentially a repeat of my first post, but I'm ready to give up. I hate to depend on the user to put the focus on the new record, but I may have to.

    Code:
     Form_Clinical_Summary_ICD10.cbo_ICD10 = Form_frmLookup_ICD10.cboICD10
                Form_Clinical_Summary_ICD10.cboICD10_Description = Form_frmLookup_ICD10.cboICD10.Column(1)
    I even tried putting this, the same code from the Form_Load into the Form_LostFocus event, but it doesn't seem to even run a test message box.
    Code:
    DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
    Well, there you have it.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Paul,
    What Allan (RG) meant was that using the prefix "Form_" in code to refer to forms is something you should never do. Access, internally and behind the scenes, adds a prefix "Form_" to the form name. You, the programmer, should refer to forms using the forms collection.

    You have
    Code:
    Form_Clinical_Summary_ICD10.cbo_ICD10 = Form_frmLookup_ICD10.cboICD10
    You should have something like
    Code:
    Forms!Clinical_Summary_ICD10.cbo_ICD10 = Forms!frmLookup_ICD10.cboICD10
    But I always have problems with referring to subforms, so it takes me a while to get it right.

    they click they click the select code button
    Don't know if the button is on the main form or subform1 ("frmLookup_ICD10"???). If the code is on the main form, you might try this syntax:
    Me!Subform2.Form!ControlName = Me!Subform1.Form!ControlName

    So if the first subform is "frmLookup_ICD10" and the second subform is "Clinical_Summary_ICD10" you might try
    Code:
    Me!Clinical_Summary_ICD10.FORM!cbo_ICD10 = Me!frmLookup_ICD10.FORM!cboICD10



    (you were not very specific: main form name or subform names, button location (main/subform) or the button code)

  5. #5
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    The select code button is on the lookup subform and copies the data just fine. When I use the new syntax.

    Code:
    Forms!Clinical_Summary_ICD10.Form!cbo_ICD10 = Forms!frmLookup_ICD10.Form!cboICD10
    I get this error.
    Click image for larger version. 

Name:	2450.JPG 
Views:	20 
Size:	19.3 KB 
ID:	26949
    While this works.
    Code:
    Form_Clinical_Summary_ICD10.cbo_ICD10 = Form_frmLookup_ICD10.cboICD10
    Running my original code works fine. What I really want to do is move the focus of form Clinical_Summary_ICD10 to record acNewRec so that the data goes in the right place. Nothing I have tried seems to work.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    In your last post you stated that it works fine *and* you get "this" error. Very confusing.

  7. #7
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Using the original syntax it works fine. The new quoted syntax produces the error.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I believe you have two SubForms. Those are displayed on your MainForm by the use of a SubFormControl. What is the name of your MainForm and what are the name of the two SubFormControls?

  9. #9
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Main Form: Clinical_Summary

    The subform control is in bold. The actual form is in blue inside the parens. There is some inconsistency in the naming convention that I usually try to avoid. Both subforms are displayed simultaneously.

    Subform1: subfrm_Clinical_Summary_ICD10 (Clinical_Summary_ICD10)
    Subform2: subfrmLookup_ICD10 (frmLookup_ICD10) This has the button with the code which copies from Subform2 to Subform1

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Based on those names and the location of the button, this should be the code behind the button to copy the value.
    Code:
       Me.Parent.subfrm_Clinical_Summary_ICD10.FORM.cbo_ICD10.SetFocus
       DoCmd.GoToRecord , , acNewRec
       Me.Parent.subfrm_Clinical_Summary_ICD10.FORM.cbo_ICD10 = Me.cboICD10
    Please try it and let us know the results.

  11. #11
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    I had high hopes for this one. It ran with no errors, but it did not perform the 2nd line.
    Code:
    DoCmd.GoToRecord , , acNewRec
    It stayed right on the 3rd record back and updated that record. Nothing in the new record. Actually I get the same results if I only run line 3.

    Code:
    Me.Parent.subfrm_Clinical_Summary_ICD10.FORM.cbo_ICD10 = Me.cboICD10
    I have noticed the focus never goes to subfrm_Clinical_Summary_ICD10.FORM.cbo_ICD10

    When I run this line by itself, the focus stays on the button I just clicked.

    Code:
    Me.Parent.subfrm_Clinical_Summary_ICD10.Form.cbo_ICD10.SetFocus
    I can set focus on anything on the Me. form, but not the destination form, so the DoCmd.GoToRecord has no effect.

    I wish I could send this to you but it's full of sensitive information and has about 40 tables with a SQL Server back end.

    I'm calling it a day. I'm grateful for all your assistance so far. I hate to give up on this, but I'm willing if your willing.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Call it a day Paul. There are many ways to skin a cat. You might try:
    Me.Parent.subfrm_Clinical_Summary_ICD10.SetFocus

    and see what happens.

  13. #13
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    And we have a winner!

    Code:
     Me.Parent.subfrm_Clinical_Summary_ICD10.SetFocus
                DoCmd.GoToRecord , , acNewRec
                Me.Parent.subfrm_Clinical_Summary_ICD10.Form.cbo_ICD10 = Me.cboICD10
                Me.Parent.subfrm_Clinical_Summary_ICD10.Form.cboICD10_Description = Me.cboICD10.Column(1)
    Would have gotten back to you sooner, but we had a snow day yesterday. Glad to bring this to a happy conclusion.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Outstanding! Thanks for posting back with your success and solution.

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

Similar Threads

  1. Get the sum in subforms
    By M_vyncci in forum Access
    Replies: 1
    Last Post: 06-29-2016, 07:11 AM
  2. Replies: 11
    Last Post: 05-13-2015, 11:10 PM
  3. Subforms Inside Subforms
    By LordPanzer in forum Access
    Replies: 1
    Last Post: 10-11-2013, 05:19 PM
  4. Subforms
    By fwillia in forum Access
    Replies: 2
    Last Post: 09-24-2010, 08:03 AM
  5. subforms
    By thewabit in forum Forms
    Replies: 6
    Last Post: 02-01-2010, 09:03 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