Results 1 to 12 of 12
  1. #1
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55

    Runtime error 2046 The Command or action Save record isn't available now. Problem

    I was testing my form to see if I could get it to fail somewhere. Well I managed to find one way that it will fail and I can’t figure out how to get it from happening.



    I have attached some Pics of my form and code.

    The first one is of my Design View showing that my form "AddToolBoradF" has 2 sub forms in it. "TemmisAddSubF" is the middle one and "TemmisItemSubF" is the bottom one.

    The second pic is showing the order I entered data to get the error to work. First I entered data in the red circles, Then I entered Data in the Yellow box, then I pressed the button in the pink box which saved the data and now it’s being displayed in the Green box, Then I entered the current data you see in the blue box, I then entered the stuff in the Orange box and finally I clicked on the pink box. That’s when the Run-Time Error 2046 pops up.

    The third pic shows what is highlighted when I click the Debug button.

    I’ve tried several things to see if I could prevent it from getting this error but none have worked and my knowledge base is still very minimal.

    Any help is greatly appreciated

    Thanks

    Munroe
    Attached Thumbnails Attached Thumbnails Form1.jpg   Form2.jpg   Form3.jpg  

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Somewhere in all that poking around, the record probably gets committed, and I believe you cannot invoke that command at that point. Instead, try
    If Me.Dirty Then
    Me.Dirty = False
    End If

  3. #3
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    I tried adding
    Code:
    If Me.Dirty Then
         Me.Dirty = False
    End If
    Just above the Yellow line in the third photo above. I also tried in the mainform "on_Activate" and "On_Deactivate" events and in the Subform "on_Activate" and "On_Deactivate" events where the "Add Temmis Item" button is. But all them did not work, i still get the same error in the same spot.

    The Line of Code "DoCmd.RunCommand acCmdSaveRecord" thats causing a problem is what i use for saving the infomation for the new temmis item. Maybe if there is another way of saving the data or having another Elseif section above the save point to get the code to mesh again...

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by MunroeM View Post
    ...But all them did not work, i still get the same error in the same spot...
    I am not sure you need the OnActivate and or the OnDeactivate events. Aside from that, the code provided to you from Micron does not 'prevent' errors from occurring. The purpose of the code is to save the form or, rather, commit changes made via bound controls to the table(s). The code will replace accmdsaverecord.

    Also, you may want to research what accmdrefresh does, exactly. It may be what you want, but it is not the same as a Requery. It is a good idea to know what each of the two methods do, specifically.

  5. #5
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    Ok i changed my code and placed the Me.Dirty code in there and i looked into refresh and requery. I changed one line to requerry but not the others as i want refresh on them.

    With the Code listed below everything works still Except i dont get the error now i just get nothing I cant even change the data in the fields marked by the yellow and blueboxes in the photos i posted I can still change the data in the mainform just not the subform. I click on the add temmis item after i have clicked outside of the subform once i have data entered in it just like i described i my first post.
    I dont know what exactly is happening but i kind of have a slight idea. It seems that if i have data entered in my subform but not saved and then i lose focus on the subform and then try and come back to it, It fails



    Code:
    '------------------------------------------------------------
    ' AddTemButton_Click
    '
    '------------------------------------------------------------
    Private Sub AddTemButton_Click()
        If IsNull(ItemName) Then
            MsgBox "Please enter the name of the temmis item.", vbCritical
            Me.ItemName.SetFocus
            Exit Sub
        ElseIf IsNull(TemmisNum) Then
            MsgBox "Please enter the temmis number.", vbCritical
            Me.TemmisNum.SetFocus
            Exit Sub
        ElseIf IsNull(ExpirationDate) Then
            MsgBox "Please enter the expiration date for the temmis item", vbCritical
            Me.ExpirationDate.SetFocus
            Exit Sub
        ElseIf IsNull(UpdatedBy) Then
            MsgBox "Please enter your name"
            Me.UpdatedBy.SetFocus
            Exit Sub
        ElseIf Me.Dirty Then
            Me.Dirty = False
            DoCmd.Requery
            'docmd.RunCommand acCmdRefresh "temp leaving this here"
            Forms![addtoolboardF].Refresh
            Forms![addtoolboardF]![TemmisItemsubF].Visible = True
            Forms![addtoolboardF]![TemmisItemsubF].Form.Refresh
        
        
        End If
        
    End Sub

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If you are using the Master and Child Link fields for your subform control, the subform and main form should refresh when you move focus from the subform to the main. Aside from that, keep in mind that not all Recordsets are updatable.

    Maybe your subform is based on a query that is not updatable. Also, you can create an updatable query that joins with other tables and or queries where some fields are updatable while other fields are not.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    The key word was 'instead'. Perhaps I should have elaborated so that you would not try to simply add the suggestion as opposed to replacing.
    The RunCommand method of the DoCmd object is used to invoke a menu selection. If a menu selection such as filter or refresh is not available because there are no records to filter or the form is not dirty, then you cannot invoke it in code either.

    As for your current problem, once you have saved the record with me.dirty = false, why requery, as this will cause the underlying query or table to be reloaded and you may lose your place in the record. This could be why you cannot edit the forms for the blue and yellow areas - perhaps now the data in your form does not jive with the underlying recordsource that you reload. Why refresh the main form (Forms![addtoolboardF].Refresh)? I'm assuming the relationship is one to many (main to subs) so it seems more likely you'd need a refresh of the subform(s), not the main. If you are only trying to affect a label or unbound textbox (such as where you have AF-234) use Recalc or less likely, Repaint. Hope I'm on the right track and this helps.
    Code:
    ....
     Me.UpdatedBy.SetFocus
     Exit Sub
    ElseIf Me.Dirty Then
      Me.Dirty = False
      Forms![addtoolboardF]![TemmisItemsubF].Visible = True
      Forms![addtoolboardF]![TemmisItemsubF].Form.Refresh

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ItsMe View Post
    ...Aside from that, keep in mind that not all Recordsets are updatable.

    Maybe your subform is based on a query that is not updatable
    ...
    This is always a good bet when this error pops up! Is the errant Form based on a Multi-Table Query?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    I finaly got the code to work and iv entered about 100 different records in all possible ways i could think of to get it to break and it worked the whole time.

    then code i ended up using is this.
    Code:
    ....
          Me.UpdatedBy.SetFocus
            Exit Sub
        ElseIf Me.Dirty Then
            Me.Dirty = False
            Forms![addtoolboardF].Refresh
            Forms![addtoolboardF]![TemmisItemsubF].Visible = True
        Else
            DoCmd.Requery
            Forms![addtoolboardF].Refresh
        End If
    End Sub
    I actually needed the "Forms![addtoolboardF].refresh" line or else the bottom sub form would not update showing which record was just created.

    I added the "else" section because when clicking away from the subform and them comming back to it made it so none of the if statments were true thats why it would not enter data and look like it was doing nothing.

    I dont know if i followed the help you were giving me the way you might have wanted me to but the help you gave me is what pushed me to getting it to work.

    so for that thanks for all the help.

    Munroe

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Glad to hear things are working well.

    I would mention that the following may not always do what you might expect it to.
    DoCmd.Requery

    The DoCmd object is a high level object. The code you used will requery what ever object has focus. A popular way to use the Requery Method is to use the Object's name you want to Requery.
    Forms!FormName.Requery
    or
    Me.Requery
    or
    Me.cmbCustomers.Requery

  11. #11
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    I replaced DoCmd.Requery with Me.Requery and it still works.

    So If i have multiple front end copies of my data base and someone presses a button then does docmd.requery does it excute that command accrsss the whole data base? so could other uses on a different front end be effected ?

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    EDIT, I forgot to mention that Docmd can do stuff to objects outside of the existing instance of the application. However, without being explicit, it is unlikely the focus would be on such an object. /EDIT

    If you are not explicit and only imply what to do with Docmd Access will decide what object you are trying to apply the statement to.

    For example, the following are all Explicit
    Code:
    Application.DoCmd.Beep
    Application.DoCmd.OpenForm "MyForm"
    Application.DoCmd.Close acForm, "NameOfForm"
    Application.DoCmd.Requery "NameOfControl"
    The following may or may not do what you expect. It depends on which Object(s) is active and, of the active objects, which Object the code can be executed against.
    Code:
    DoCmd.Close
    DoCmd.Requery

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

Similar Threads

  1. Replies: 3
    Last Post: 01-02-2015, 02:06 PM
  2. Replies: 4
    Last Post: 12-12-2014, 08:48 AM
  3. runtime error 2501 openform action was canceled
    By rumenrs in forum Programming
    Replies: 2
    Last Post: 04-11-2013, 04:29 AM
  4. Replies: 13
    Last Post: 10-19-2012, 06:34 AM
  5. Replies: 3
    Last Post: 06-09-2012, 08:14 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