Results 1 to 9 of 9
  1. #1
    brian11670 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    7

    Getting run time error 2455 using Form Current event


    All,
    I have a Current event set on a subform A that is trying to change the source and requery several other subforms when the selected record changes in subform A.
    I am getting RUN TIME ERROR 2455 "You entered an expression that has an invalid reference to the property form/report".

    Code:
    Private Sub Form_Current()
    Dim qdf As DAO.QueryDef
    
    
    gVarMbrId = Me.MEMBER_ID
    strMbr = GetMember()
    
    
    Set qdf = CurrentDb.QueryDefs("PassThrough_MBR_ENRLMNT")
    qdf.SQL = "EXEC [dbo].[WF_FETCH_MBR_ENRLMNT] '" & strMbr & "'"
      
      
    'Enrollment
    Forms!Frm_Task_List_Detail!PassThrough_MBR_ENRLMNT_subform.Form.RecordSource = "SELECT * FROM PassThrough_MBR_ENRLMNT"
    Forms!Frm_Task_List_Detail!PassThrough_MBR_ENRLMNT_subform.Form.Requery
    
    
    'RevOpt
    Forms!Frm_Task_List_Detail!dbo_WF_REVOPT_HCCs_subform.Form.RecordSource = "SELECT * FROM Qry_RevOpt_Member_HCCs WHERE MBRID = '" & strMbr & "' ORDER BY CLM_SRVC_DT desc"
    Forms!Frm_Task_List_Detail!dbo_WF_REVOPT_HCCs_subform.Form.Requery
      
    'Edward
    Forms!Frm_Task_List_Detail!PassThroughMbrHccQuery_subform.Form.RecordSource = "SELECT * FROM Qry_Mbr_Hcc_Query WHERE member_id = '" & strMbr & "' ORDER BY ENSTRTDT desc"
    Forms!Frm_Task_List_Detail!PassThroughMbrHccQuery_subform.Form.Requery
    
    
    
    
    
    
    End Sub
    What is strange is this code above works fine if I use it on an individual text box OnClick event in the same subform A.
    Any idea what I am doing wrong r missing? Any help is greatly appreciated.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    No ideas as to why, but if you change a recordsource, there is no need to requery?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Just curious why not have a textbox on the main form populated with the strMbr string (in the current event) and then simply use master\child linking for the subforms?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Always state which line is causing the error. You have 3 somewhat similar references (6 if you want to count them all). We're left guessing.
    Maybe you left one subform control with the default name of "Child#" where # is some number. In other words, the syntax may be correct but the references are not. Often it's just an invalid spelling/reference?

    EDIT - even if it works on another event, the above could still apply - if you retyped it and it is correct in the working procedure. If it errs on the first reference, rem it out and see what happens on subsequent lines. I agree that if a recordsource is altered, it doesn't seem to need a requery.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    brian11670 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    7
    Quote Originally Posted by Micron View Post
    Always state which line is causing the error. You have 3 somewhat similar references (6 if you want to count them all). We're left guessing.
    Maybe you left one subform control with the default name of "Child#" where # is some number. In other words, the syntax may be correct but the references are not. Often it's just an invalid spelling/reference?

    EDIT - even if it works on another event, the above could still apply - if you retyped it and it is correct in the working procedure. If it errs on the first reference, rem it out and see what happens on subsequent lines. I agree that if a recordsource is altered, it doesn't seem to need a requery.

    It errors on this line:

    Code:
    'Enrollment
    Forms!Frm_Task_List_Detail!PassThrough_MBR_ENRLMNT_subform.Form.RecordSource = "SELECT * FROM PassThrough_MBR_ENRLMNT"

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    If it errs on the first reference, rem it out and see what happens on subsequent lines.
    What is the answer to that question/suggestion.

    Also, I've read some confusing posts about form controls (including subform controls) not being 'loaded' if the form has no records but could not make sense out of whether that applied to the main form or subform. Suggest you ensure that those recordsources actually produce records. Also, perhaps worth keeping in mind that
    - subforms load first, so you cannot usually reference main form fields or properties from subform Open, Load or Current events
    - AFAIK, Current event is the last form event to fire when you open a form. It doesn't just run when you change records, so your code is running as a result of form opening.

    If I may, I'd also suggest some notes in your code so we don't have to make too many assumptions about what's going on. I'm beginning to think that you're trying to modify a property for the main form (not just some other form that is already open) and the first time that code is called, the main form hasn't loaded yet. If that is the cause, you might want to move the recordsource code to a main form event.

    What is strange is this code above works fine if I use it on an individual text box OnClick event in the same subform A.
    Now that I've thought more about it, that makes perfect sense - the main form definitely is loaded at that point.
    Last edited by Micron; 09-07-2021 at 08:41 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    brian11670 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    7
    Quote Originally Posted by Micron View Post
    What is the answer to that question/suggestion.

    Also, I've read some confusing posts about form controls (including subform controls) not being 'loaded' if the form has no records but could not make sense out of whether that applied to the main form or subform. Suggest you ensure that those recordsources actually produce records. Also, perhaps worth keeping in mind that
    - subforms load first, so you cannot usually reference main form fields or properties from subform Open, Load or Current events
    - AFAIK, Current event is the last form event to fire when you open a form. It doesn't just run when you change records, so your code is running as a result of form opening.

    If I may, I'd also suggest some notes in your code so we don't have to make too many assumptions about what's going on. I'm beginning to think that you're trying to modify a property for the main form (not just some other form that is already open) and the first time that code is called, the main form hasn't loaded yet. If that is the cause, you might want to move the recordsource code to a main form event.

    Now that I've thought more about it, that makes perfect sense - the main form definitely is loaded at that point.

    Thank you for your thoughts on this and I think you are right in saying: "Suggest you ensure that those recordsources actually produce records. Also, perhaps worth keeping in mind that
    - subforms load first, so you cannot usually reference main form fields or properties from subform Open, Load or Current events"

    Initially I have the main form and subforms open blank (no records). I have combo boxes for the user to select from to populate the subforms. Once they make their selections to populate the subforms then I was going to use the CURRENT trigger to refresh some of the subforms based on the value of a field in the current active record.

  8. #8
    brian11670 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    7
    I tried this but the problem is the dataset is large and it was taking a long time (4-5 minutes) to populate the subform because it has to drag the table across the network then perform the master\child linking.
    I forgot to mention this MS Access application is a front end app with a backend SQL Server.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    If the combos are on the main form, use their AfterUpdate event? The current event fires as I noted, but also every time you select a different record on a form. I don't think you should have code that sets properties such as RecordSource in the current event. Perhaps you'd be better off if you make use of the Master and Child field properties of the main/sub form and allowed the subform to populate based on the main form records that are loaded (or not) after the combo AfterUpdate event.
    so you cannot usually reference main form fields or properties from subform Open, Load or Current events
    I think I made that sound a little bit too rigid. Should have said sometimes, not "usually" and it depends on what you're trying to do.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 5
    Last Post: 03-13-2020, 02:27 PM
  2. Replies: 21
    Last Post: 07-26-2018, 11:50 AM
  3. Search Code with error 2455
    By scoe in forum Forms
    Replies: 2
    Last Post: 10-22-2014, 01:55 AM
  4. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  5. Replies: 8
    Last Post: 04-29-2013, 11:23 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