error "The command or action 'SaveRecord' isn't available now"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ilucks
    New Member
    • Mar 2007
    • 6

    error "The command or action 'SaveRecord' isn't available now"

    I converted Acc97 to Acc2003 and got this error "The command or action
    'SaveRecord' isn't available now" when i tried to open one form"Add
    Info form", which has Save button. I checked "reference" in Tool to
    see DAO 3.6 object library setting, and it was right.
    How can i resolve this error?
    Thanks.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by ilucks
    I converted Acc97 to Acc2003 and got this error "The command or action
    'SaveRecord' isn't available now" when i tried to open one form"Add
    Info form", which has Save button. I checked "reference" in Tool to
    see DAO 3.6 object library setting, and it was right.
    How can i resolve this error?
    Thanks.
    What code exactly are you using on the save record button.

    Comment

    • ilucks
      New Member
      • Mar 2007
      • 6

      #3
      Originally posted by mmccarthy
      What code exactly are you using on the save record button.
      Clickevent and commandbutton - Save button

      where can i add this line in the code?
      If Me.Dirty Then RunCommand acCmdSaveRecord

      Code:
      Private Sub Save_Button_Click()
      On Error GoTo Err_Save_Button_Click
      
        Dim MyDB As Database, MyTable As Recordset
        Set MyDB = DBEngine.Workspaces(0).Databases(0)
      
          Dim MyTable4 As Recordset
          Set MyTable4 = MyDB.OpenRecordset("Tax Map")
          MyTable4.Index = "PrimaryKey"
          MyTable4.Seek ">=", Me![Add Tax Map Info SubForm].Form![State Code], Me![Add Tax Map Info SubForm].Form![COUNTY CODE], Me![Add Tax Map Info SubForm].Form![TOWNSHIP CODE], Me![Add Tax Map Info SubForm].Form![Tax Map], Me![Add Tax Map Info SubForm].Form![Alternate ID]
          Do Until MyTable4.EOF Or MyTable4.NoMatch
          If MyTable4![State Code] = Me![Add Tax Map Info SubForm].Form![State Code] And MyTable4![COUNTY CODE] = Me![Add Tax Map Info SubForm].Form![County] And MyTable4![TOWNSHIP CODE] = Me![Add Tax Map Info SubForm].Form![Township] And MyTable4![Tax Map] = Me![Add Tax Map Info SubForm].Form![Tax Map] And MyTable4![Alternate ID] = Me![Add Tax Map Info SubForm].Form![AltID] Then
              MyTable4.Edit
              MyTable4![Title Opinion #] = Me![Add Tax Map Info SubForm].Form![Title Opinion #]
              MyTable4.Update
              Exit Do
          Else
              MyTable4.MoveNext
          End If
          Loop
        
        Set MyTable = MyDB.OpenRecordset("Interested Parties")
      'Stop
          MyTable.AddNew
              MyTable![LEASE NUMBER] = Forms![LEASE DATA COPY FORM ONLY]![LEASE NUMBER]
              MyTable![SURFACE#] = "S0000"
              MyTable![Division#] = Me![Division]
              MyTable![Last Name] = Me![Last Name]
              MyTable![First Name] = Me![First Name]
              'other things are the same way
          MyTable.Update        
        
      'SAVE INFORMATION TO THE "INTERESTS/TAX MAP" TABLE FROM THE "NEW INTEREST TAX MAP SETUP" TABLE
          Dim MyTable2 As Recordset, MyTable3 As Recordset
          Set MyTable2 = MyDB.OpenRecordset("Interest/Tax Map")
          Set MyTable3 = MyDB.OpenRecordset("New Interest Tax Map Setup")
          Do Until MyTable3.EOF
          MyTable3.MoveFirst
              Do Until MyTable3.EOF
              If IsNull(MyTable3![State Code]) Then
                  MyTable3.MoveNext
              Else
       MyTable2.AddNew
                  MyTable2![LEASE NUMBER] = MyTable3![LEASE NUMBER]
                  MyTable2![SURFACE#] = "S0000"
                  MyTable2![Division#] = MyTable3![Division#]
                  MyTable2![State Code] = MyTable3![State Code]
                  'skip other things 
                  MyTable2.Update
                  MyTable3.MoveNext
              End If
              Loop 
      
      'DELETE ALL RECORDS FROM THE "NEW INTEREST TAX MAP SETUP TABLE
          MyTable3.MoveFirst
          Do Until MyTable3.EOF
              MyTable3.Delete
              MyTable3.MoveNext
          Loop
          Loop
       DoCmd.SetWarnings False
       'SAVE RECORDS FROM THE "TAX MAP/UNITS Temp" TABLE TO THE "TAX MAP/UNITS" TABLE
          Dim stDocName As String
          stDocName = "Append to Tax Map/Units Table"
          DoCmd.OpenQuery stDocName, acNormal, acEdit
       'DELETE RECORDS FROM THE "TAX MAP/UNITS Temp" TABLE
          stDocName = "Delete Tax Map/Units Temp Table"
          DoCmd.OpenQuery stDocName, acNormal, acEdit
          
      'SAVE RECORDS FROM THE "TAX MAP/PROSPECTS Temp" TABLE TO THE "TAX MAP/PROSPECTS" TABLE
          stDocName = "Append to Tax Map/Prospects Table"
          DoCmd.OpenQuery stDocName, acNormal, acEdit
      'DELETE RECORDS FROM THE "TAX MAP/PROSPECTS Temp" TABLE
          stDocName = "Delete Tax Map/Prospects Temp Table"
          DoCmd.OpenQuery stDocName, acNormal, acEdit
         
      DoCmd.SetWarnings True
      DoCmd.Close
          
      Exit_Save_Button_Click:
          Exit Sub
      
      Err_Save_Button_Click:
          MsgBox Err.DESCRIPTION
          Resume Exit_Save_Button_Click
          
      End Sub
      Thanks.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Originally posted by ilucks
        Clickevent and commandbutton - Save button

        where can i add this line in the code?
        If Me.Dirty Then RunCommand acCmdSaveRecord
        I'm not sure what you mean. The code you have given uses recordsets to save data. The line of code above would save a record if any changes had been made on a form. However, this would happen automatically on a bound form.

        Mary

        Comment

        • ilucks
          New Member
          • Mar 2007
          • 6

          #5
          Thank you for your tip.

          I have a few more questions about it.
          As i mentioned before, i converted this DB to access 2002 and tried to open an unbound form from the bound form.
          so like this. I have
          1. open a bound form A ( Customer)
          2. enter a customer number and click Add info button,which is an unbound form to add more information. Here is the problem occurred.
          It says error "The command or action 'SaveRecord' isn't available now"
          can you tell me about more how this happenning in the bound or unbound form?
          you're saying that the code in Add Info form(unbound) shouldn't cause this error.
          what about in Form A? by the way, a user
          why does this happen?
          how does a subform work after the conversion?
          i just noticed that a subform(bound form) in Form A displays just like a normal form. In other words, i checked the properties of this subform and it doesn't say subform propeties.just says "Form".



          i am a beginner in access programming.
          I would appreciaste your help.

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Bound forms are bound to a table or query and will save records and changes to records directly to the tables. An unbound form is just a visual graphic. The data is only held as long as the form is open.

            You have tried to get around this by adding the data via recordsets but if you are trying to tie that new record in the bound form then this won't work as this record is not yet saved.

            Why is the second form unbound?

            Using subforms there is a Form that the object is based on and a subform object which is the object on the Main Form.

            Mary

            Comment

            • ilucks
              New Member
              • Mar 2007
              • 6

              #7
              Originally posted by mmccarthy
              Bound forms are bound to a table or query and will save records and changes to records directly to the tables. An unbound form is just a visual graphic. The data is only held as long as the form is open.

              You have tried to get around this by adding the data via recordsets but if you are trying to tie that new record in the bound form then this won't work as this record is not yet saved.

              Why is the second form unbound?

              Using subforms there is a Form that the object is based on and a subform object which is the object on the Main Form.

              Mary
              Why is the second form unbound?
              it was like this before i came to work here..
              When does this error happen?
              The DB in access 97 works fine, but not the converted one, why?
              I checked other forms and they just display data.
              This is the only form has a savebutton but you told me the code uses recordset to save data. where else do i have to check?

              thanks

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                What the unbound form is doing is not incorrect but it's very difficult to guide you through a conversion as your knowledge of VBA is limited.

                There is no save command as such in this code which means the error is probably referring to one of the recordset update commands. I don't know why it's not working as there are many possibilities which could extend to the queries.

                When the error comes up, do you get a debug option? If so what line of code does it stop at?

                Mary

                Comment

                • ilucks
                  New Member
                  • Mar 2007
                  • 6

                  #9
                  Originally posted by mmccarthy
                  What the unbound form is doing is not incorrect but it's very difficult to guide you through a conversion as your knowledge of VBA is limited.

                  There is no save command as such in this code which means the error is probably referring to one of the recordset update commands. I don't know why it's not working as there are many possibilities which could extend to the queries.

                  When the error comes up, do you get a debug option? If so what line of code does it stop at?

                  Mary
                  No, i didn't get the debug option.
                  In the bound form(Form A), i get this message when i click Add Info button.
                  By the way, i found out that this Add Info form has two bound forms associated with.lol
                  Again,
                  1. i open Form A(the bound form)
                  2. click Add Info button to add additional info - i get an error message
                  what is If Me.Dirty then Me.Dirty = false
                  when can i use and how?
                  What is this?
                  If Me.Dirty Then
                  DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

                  Thank you much
                  End If

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by ilucks
                    No, i didn't get the debug option.
                    In the bound form(Form A), i get this message when i click Add Info button.
                    By the way, i found out that this Add Info form has two bound forms associated with.lol
                    Again,
                    1. i open Form A(the bound form)
                    2. click Add Info button to add additional info - i get an error message
                    what is If Me.Dirty then Me.Dirty = false
                    when can i use and how?
                    This clears the form of any new or edited data.

                    Originally posted by ilucks
                    What is this?
                    If Me.Dirty Then
                    DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
                    This says if changes have been made then save the record. However, this won't work on an unbound form.

                    Comment

                    • sierra7
                      Recognized Expert Contributor
                      • Sep 2007
                      • 446

                      #11
                      Hi
                      I have just the same error message in similar circumstances; forms that run ok in '97 but error after conversion to 2002/3, so thought I'd add to this thread.

                      My situation is that after opening the [Sales Order History] listing form the user can pop-open the main [Sales Orders] in READ ONLY format which is when the error occurs. Microsoft's reason is ;-

                      "Access 2000 only looks at the AllowEdits property when making this determination, when it should be looking at both the AllowEdits and the AllowAdditions properties." - kb 280521 (similar but not same problem)

                      Microsoft's recommendation was to load latest Service Pack but that did not work for me so I changed the code as below.
                      Code:
                         stDocName = "SalesOrders"    
                        stCalledFrom = "Previous"
                        stLinkCriteria = "[OrderID]=" & Me![OrderID]
                      
                        DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly, acDialog
                      
                      'change last line to 
                        DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
                      I tried to hold off the save if nothing had changed with ;-
                      Code:
                      If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
                      but that did not work even though the form itself should not have been 'dirty'. When witing the code I think I had to force a 'save' to keep various audit functions current (because it is some years since I wrote this)

                      S7

                      Comment

                      • DonRayner
                        Recognized Expert Contributor
                        • Sep 2008
                        • 489

                        #12
                        Originally posted by ilucks
                        I converted Acc97 to Acc2003 and got this error "The command or action
                        'SaveRecord' isn't available now" when i tried to open one form"Add
                        Info form", which has Save button. I checked "reference" in Tool to
                        see DAO 3.6 object library setting, and it was right.
                        How can i resolve this error?
                        Thanks.
                        I have the same problem with some of my forms. I'm using the same form for Adding / Editing / Viewing records with subforms on a tab control. The subforms are linked to different tables that link back to the main table. The save command has to be in there for when adding new records so that records don't get saved into the tables without the the main table being saved.

                        I just got around the problem by trapping the error.

                        Public Sub (YourSubName)
                        On Error GoTo ErrPoint

                        Your code goes here

                        ExitPoint:
                        Exit Sub

                        ErrPoint:
                        If Err.Number = 2046 Then
                        Resume Next
                        Else
                        MsgBox "Error# " & err.number & " " & Err.Description
                        Resume ExitPoint
                        End If

                        You can use whatever code you want in place of the MsgBox, I personally call my own error traping sub form there that places all the error information into a table so I can use it for debuging later.

                        Don

                        Comment

                        • BILL987
                          New Member
                          • Feb 2017
                          • 1

                          #13
                          I was running into the same issue.

                          I think I've figured it out. At least for me. I did a quick check and it seems that if your FORM is going after more than 1 table it doesn't know where to save the info. So I'm trying a work around. Creating a table with all data fields active with no links or relationships.

                          Hope it works for you guys too.

                          ~Bill

                          Comment

                          Working...