Results 1 to 2 of 2
  1. #1
    banditson is offline Novice
    Windows Vista Access 2000
    Join Date
    Feb 2011
    Posts
    1

    Unhappy how do I add code to the close command and where do I put it?

    I am just begining to work with code so, this may be simple? I have created a form command that closes a form, maximizes the ribbon, opens a table and deletes any records in it. I will then append records to that table. I would then like to close the table and reopen the "info form" again. How and where do I write the code to do this? You can see that I have the close command line commmented out below. I think that is correct but, where do I do all of this?
    Private Sub Option32_Click()
    DoCmd.OpenTable "xxx xxx", acViewNormal, acEdit
    DoCmd.Maximize
    DoCmd.close acForm, "Info Form", acSaveYes


    DoCmd.ShowToolbar "Ribbon", acToolbarYes
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdDelete
    ''DoCmd.close acTable, "PIP PINS", acSaveYes
    End Sub

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you're deleting all of the records in a table. that is NOT the way to do it. the way TO do it is like this:
    Code:
    currentdb.execute "delete * from [xxx xxx]"
    one line of code, DONE.

    now trust me, I'm not making light of your concerns, but this is a classic example of novice coding, and it's simply because beginners usually tend to cling to the "docmd" object, because it has one of the largest dropdown items for the intellisense in VBA, second to only the "docmd.runcommand" code, which has hundreds of commands to execute (I think). the other thing is that beginners tend to use it because the "wording" of the dropdown items can be significantly correlated with interface features and menus. Hence, interface users identify well with the menu, and furthermore, know what it means.

    that's the very first thing you need to do here.

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

Similar Threads

  1. Count Down and close on date code
    By ibraomer in forum Programming
    Replies: 1
    Last Post: 01-03-2011, 08:58 PM
  2. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 PM
  3. close form code not releasing recordsource..
    By dmeehanjr in forum Forms
    Replies: 1
    Last Post: 08-12-2010, 05:42 PM
  4. Form/report command button code
    By max3 in forum Forms
    Replies: 1
    Last Post: 08-26-2009, 02:18 AM
  5. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM

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