Form_Load event not firing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    Form_Load event not firing

    I've got a form whose Form_Load event isn't running. The Form_Open event runs fine as do the button's on the form. I have removed the link in the properties window and recreated the event as was suggested by all the online forums. I have a breakpoint setup on the first line of executable code and it doesn't do anything. I don't know what else to try.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    What does the value in the Property window say for Load?

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      Copy/Paste = [Event Procedure]. I wiped that out, and clicked on the ellipsis, selected Code Builder and it went directly to my code.

      I'm opening it as a Dialog window and I have it's Modal and Pop Up properties set to Yes. There are no subforms involved. I don't think that these setting make any difference on what events fire as I have used these properties before and never had any trouble, but I thought that I would mention it.
      Last edited by Seth Schrock; Oct 10 '14, 06:08 PM. Reason: Added Info

      Comment

      • jforbes
        Recognized Expert Top Contributor
        • Aug 2014
        • 1107

        #4
        If you are sure that it should be running, but it isn't you might be getting into a bit of corruption.

        A few things to try:
        • Copy your Form, Recompile and Save. Then test with your Copied Form.
        • Blow away all the code for the Form_Load (Copy to a text file first). Compile and Save, then re-open, and attempt to add it again by clicking the Event Ellipse on the Property Window.
        • Create a new Form and paste your startup code into the Form_Load and see if it gets Executed. If so, copy the controls and the rest of the code over, Copy over the properties on your Form, re-setup all the Events for your controls by clicking on the Event Ellipse on the controls Property then selecting Code Builder. .. I know this doesn't sound like fun, but it might get you past your problem.
        • If all else fails, create a new Database and Import all the objects.


        Visual Studio/Winforms likes to do this every so often and the easiest way to fix it is to edit the Form Source, but that's really not an option here.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          Numbers 1 and 2 didn't work, but number 3 seems to be working. Now to start copying over 160 lines of code...

          I had just created the event too. It never did work. I'm starting to get several corrupted forms now. Very frustrating.

          Comment

          • jforbes
            Recognized Expert Top Contributor
            • Aug 2014
            • 1107

            #6
            Make backup copies as soon as possible. You may need to resort to importing into a new database soon. =(

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              If I remove the link to the Form_Open event, everything works fine. If I reconnect the link to the Form_Open event, the Form_Load event doesn't fire. I have verified this on both the old and the new (from scratch) forms.

              Here is what I have in the Form_Open event:
              Code:
              Dim strSQL As String
              
              strSQL = "SELECT CS.CustID_fk, S.Service, CS.Used " & _
                       "FROM Options_Services AS S INNER JOIN Customer_CustomerServices AS CS " & _
                       "ON S.ServiceID_pk = CS.ServiceID_fk " & _
                       "WHERE CustID_fk = " & g_CustomerID
                       
              Set db = CurrentDb
              Set rst = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
              Set Me.Recordset = rst
              
              Me.Service.ControlSource = "Service"
              Me.Used.ControlSource = "Used"
              Both the db and rst variables are declared as module level variables. Does this help it make sense that the Form_Load event isn't firing?

              Comment

              • jforbes
                Recognized Expert Top Contributor
                • Aug 2014
                • 1107

                #8
                This seems fun.

                Instead of this:
                Code:
                Dim strSQL As String
                 
                 strSQL = "SELECT CS.CustID_fk, S.Service, CS.Used " & _
                          "FROM Options_Services AS S INNER JOIN Customer_CustomerServices AS CS " & _
                          "ON S.ServiceID_pk = CS.ServiceID_fk " & _
                          "WHERE CustID_fk = " & g_CustomerID
                 
                 Set db = CurrentDb
                 Set rst = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
                 Set Me.Recordset = rst
                Maybe try:
                Code:
                Dim strSQL As String
                 
                 strSQL = "SELECT CS.CustID_fk, S.Service, CS.Used " & _
                          "FROM Options_Services AS S INNER JOIN Customer_CustomerServices AS CS " & _
                          "ON S.ServiceID_pk = CS.ServiceID_fk " & _
                          "WHERE CustID_fk = " & g_CustomerID
                
                Me.RecordSource = strSQL
                Also, what is happening in Form_Open? I doubt there would be something to actually stop Form_Load, but it's possible.

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  I'm using transaction commit/rollback, so I think that I need to have it be Recordset and not RecordSource. However, I'm no expert on this type of solution, so I may be wrong. I could test it though to see if setting the form's recordset in the Form_Open event is stopping the Form_Load event from running. To me, that would make no sense, but that doesn't mean anything.

                  Comment

                  • Seth Schrock
                    Recognized Expert Specialist
                    • Dec 2010
                    • 2965

                    #10
                    Bingo. If I comment out line 10 in post #7, then the Form_Load event runs. If I uncomment it, Form_Load doesn't run. Now to test the transaction Commit/Rollback functionality without using Recordset.

                    Has anyone else noticed this? I checked Allen Browne's list of bugs, but didn't see it listed.

                    Comment

                    Working...