Timing issues with Access & SQL Server again

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rocky Road
    New Member
    • Nov 2006
    • 3

    #1

    Timing issues with Access & SQL Server again

    I'm using Access 2002 as a front end to a SQL Server 2000 database. I Update a status field in a SQL Server table using a parameter based stored proc. Works great. Then in the same sub, I open a popup form to view the record I have just updated.

    If I open the Popup Form automatically in code, the status field is not updated. If I open it from a button on the form, it works great.

    I have tried every trick I know to force the SQL Server table to be updated before I open the Popup Form, but nothing works. I have tried (1) Doevents, (2) Requerying the Popup Form, (3) Requerying the updated recordset (4) Opening the updated recordset in code.

    Any other Suggestions?
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by Rocky Road
    I'm using Access 2002 as a front end to a SQL Server 2000 database. I Update a status field in a SQL Server table using a parameter based stored proc. Works great. Then in the same sub, I open a popup form to view the record I have just updated.

    If I open the Popup Form automatically in code, the status field is not updated. If I open it from a button on the form, it works great.

    I have tried every trick I know to force the SQL Server table to be updated before I open the Popup Form, but nothing works. I have tried (1) Doevents, (2) Requerying the Popup Form, (3) Requerying the updated recordset (4) Opening the updated recordset in code.

    Any other Suggestions?
    Don't know the solution offhand Rocky will point some experts in your direction who might.

    Mary

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      As a last resort (because you've already considered most answers I could think of - especially the DoEvents one) can you try using the OnTimer routine.
      Open the popup form in the Timer event and trigger the event after, say, a quarter of a second.
      A bit of a clumsy work-around, but should reproduce the manual method which is working quite closely.
      HTH.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by Rocky Road
        I'm using Access 2002 as a front end to a SQL Server 2000 database. I Update a status field in a SQL Server table using a parameter based stored proc. Works great. Then in the same sub, I open a popup form to view the record I have just updated.

        If I open the Popup Form automatically in code, the status field is not updated. If I open it from a button on the form, it works great.

        I have tried every trick I know to force the SQL Server table to be updated before I open the Popup Form, but nothing works. I have tried (1) Doevents, (2) Requerying the Popup Form, (3) Requerying the updated recordset (4) Opening the updated recordset in code.

        Any other Suggestions?
        Is it possible to see the offending snippet of code?

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          I know absolutely nothing about writing to a SQL Server backend, but by your description of the problem, it sounds like it's not writing the update to the backend until the focus moves off of wherever it is to the button to open the popup. You might try in VBA moving the focus elsewhere then opening the form from VBA. Won't take but a second to try!

          Comment

          • Andrew Thackray
            New Member
            • Oct 2006
            • 76

            #6
            The issue probably is with the type of cursor you opened in the recordset.

            I've had this problem myself & found if I replace the recordset.updat e command with the Recordset.updat ebatch coimmand the database is updated immediately. Otherwise the command is not committed unti lyou leave the procedure or close the connection

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by Andrew Thackray
              The issue probably is with the type of cursor you opened in the recordset.

              I've had this problem myself & found if I replace the recordset.updat e command with the Recordset.updat ebatch coimmand the database is updated immediately. Otherwise the command is not committed unti lyou leave the procedure or close the connection
              Far too many answers without seeing code.
              Don't know if it is dao, ado, odbc, recordset, command object, connection object, server side cursor blah blah blah.
              Post the code

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Long time no see Andrew.
                This sounds like the proper answer to me.
                You won't need the timer trick if this works.

                Comment

                • Rocky Road
                  New Member
                  • Nov 2006
                  • 3

                  #9
                  Originally posted by willakawill
                  Far too many answers without seeing code.
                  Don't know if it is dao, ado, odbc, recordset, command object, connection object, server side cursor blah blah blah.
                  Post the code
                  Here's the code. Remarked out lines are some of the code I have tried to use to resolve this issue.

                  Code:
                     '*******
                     ' StoredProc set PositionStatus = Previous and PositionEndDate = @PositionEndDate in EmployeePosition
                     ' WHERE PositionStatus = Current and EmployeeID = @EmployeeID
                  
                     cnn.BeginTrans
                     Set cmd = MakeStoredProc("sp_EmployeePosition_UpdatePositionEndDateNStatus_ForEmployeeID")
                     Set prmEmployeeID = cmd.CreateParameter("EmployeeID", adInteger, adParamInput, , lngEmployeeID)
                     Set prmPositionEndDate = cmd.CreateParameter("PositionEndDate", adDate, adParamInput, , datTermination)
                     Set prmModName = cmd.CreateParameter("ModName", adVarChar, adParamInput, 6, gbStrUserCode)
                     cmd.Parameters.Append prmEmployeeID
                     cmd.Parameters.Append prmPositionEndDate
                     cmd.Parameters.Append prmModName
                     cmd.Execute
                     cnn.CommitTrans
                     Set cmd = Nothing
                     DoEvents
                  
                  '   Set qryd1 = gbDbsUser.QueryDefs("EmployeePosition_Update1PositionEndDate2Status_ForEmplID_UpdQry")
                  '   qryd1.Parameters("prmEmployeeID") = lngEmployeeID
                  '   qryd1.Parameters("prmPositionEndDate") = datTermination
                  '   qryd1.Parameters("prmModName") = gbStrUserCode
                  '   qryd1.Execute
                  '   DoEvents
                  '   qryd1.Close: Set qryd1 = Nothing
                  
                  '   Set tdfEmployeePosition = gbDbsUser.TableDefs("EmployeePosition")
                  '   var = RefreshMyLink(tdfEmployeePosition, tdfEmployeePosition.Connect)
                  
                  '   Set cnn = gbCnnDataDB
                  '   DoEvents
                  
                     '-- Open VacantPosition_Popup
                     MyW = "EmployeeID = " & lngEmployeeID
                     var = OpenMyForm("EmployeePosition_TerminateEmployee_Popup", "Popup", "Employee_Entry", MyW)
                  
                     '-- Confirm End
                     myM = "CURRENT EMPLOYEE POSITIONS HAVE BEEN SET TO PREVIOUS. Open the Employee Position Terminate " _
                           & "Popup to set the Position to Vacant. "
                     Alert

                  Comment

                  • willakawill
                    Top Contributor
                    • Oct 2006
                    • 1646

                    #10
                    Originally posted by Rocky Road
                    Here's the code. Remarked out lines are some of the code I have tried to use to resolve this issue.
                    As I suspected. There is no recordset object. Now would you please post the code for the declarations of the cnn and cmd objects. Thanks

                    Comment

                    • Rocky Road
                      New Member
                      • Nov 2006
                      • 3

                      #11
                      Originally posted by willakawill
                      As I suspected. There is no recordset object. Now would you please post the code for the declarations of the cnn and cmd objects. Thanks
                      Thanks for your help. I found the problem. There was an error in my OpenMyForm Function.

                      Comment

                      • MMcCarthy
                        Recognized Expert MVP
                        • Aug 2006
                        • 14387

                        #12
                        Originally posted by Rocky Road
                        Thanks for your help. I found the problem. There was an error in my OpenMyForm Function.
                        Glad you got it worked out.

                        Mary

                        Comment

                        Working...