Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2009
    Posts
    7

    Unhappy Adding Command Button To Form


    I am using Access 2000. Evidently adding a Command Button isn't as cut and dry as clicking on it, selecting a location on your form, and going through the wizard and choosing what you want. I have added a Save Record & Add Record to my form. Evidently some VB coding is required. Which, I don't see why the option is there to add a button through the wizard w/ preset names (ex - Save Record, Add Record, Next Record, etc..) if they don't automatically work when you use them. Can anybody help me!?! I am familar with access, but have no idea about this VB coding stuff. So if you have the time and decide to answer my question I would need to know step-by-step how to incorporate anything that requires code to make this work. I don't understand ANY VB AT ALL!!!! Yeah, I'm pitiful. The 1st step is admittance. The 2nd step is YOU helping me. I'm about to lose my mind..........

  2. #2
    rommelgenlight is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2009
    Posts
    77
    sure thing.

    to make a command button to add a record that you have input in your form, the step are:

    1. right click the command button for your add purpose and click properties
    2. goto event table and double click the field in the On Click
    3. you will see now [Event Procedure]. Then click the "..." button on its right
    4. now your in the microsoft visual basic where you are to code

    now it will look like this:

    Option Compare Database
    -------------------------------------------------------
    Private Sub Command2_Click()

    End Sub

    5. in between Private Sub command2_click() and End Sub is a space where you are code.
    6. and the code to add new record is

    DoCmd.GoToRecord , , acNewRec

    7. Actually, when you type docmd., you will notice that you have a guide what next code are to be completed, you only need to follow.

    8. then goto its microsoft visual basic menu bar and you will find DEBUG then click compile

    9. compiling and saving would be the last thing to do after each and every coding you make.

    try it yourself.

  3. #3
    Join Date
    Mar 2009
    Posts
    7
    This is the code on the "Add Record" button:

    Private Sub Add_Record_Click()
    On Error GoTo Err_Add_Record_Click


    DoCmd.GoToRecord , , acNewRec

    Exit_Add_Record_Click:
    Exit Sub

    Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click

    End Sub


    What do I do with it!?!

  4. #4
    rommelgenlight is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2009
    Posts
    77
    put that in your On Click event of your command button of adding.

  5. #5
    Join Date
    Mar 2009
    Posts
    7
    This is what I got when I added the above code in there and attempted to use it:

    Microsoft Access can't find the macro 'Private Sub Add_Record_Click() On
    Error GoTo Err_Add_Record_Click


    DoCmd.'

    The macro doesn't exist, or the macro is new but hasn't been saved.

  6. #6
    Join Date
    Mar 2009
    Posts
    7
    I guess I would like to know why do I go through the wizard for adding the command button and the button not work. You would think it would put the code in there for you being that the options for what kind of button you want are already pre-written in the wizard. Just seems kind of silly to me that you would create the button using their process and it not work automatically. I dunno............memoirs of a non-coder.

  7. #7
    Join Date
    Mar 2009
    Posts
    7
    Got it! I google and someone answered this question in this forum and got an easy answer. He said he creates a macro that saves, closes, & reopens the form. I was able to do that..........viola!!!!

  8. #8
    marianne is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Asia Pacific Region
    Posts
    150
    good for you uneek78. but macro is not the visual basic coding ok. i guess if you use wizard and its autogenerated codes are functioning, then you need to re-install your ms access application. maybe there is a problem there.

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

Similar Threads

  1. Duplicate command button
    By brettg in forum Database Design
    Replies: 1
    Last Post: 08-04-2008, 04:16 AM
  2. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM
  3. Command button for time & date
    By joet5402 in forum Forms
    Replies: 2
    Last Post: 12-20-2007, 02:59 AM
  4. command button to filter a subform issue -
    By countdrako in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 11:58 PM
  5. Open a linked subform with a command button
    By flablueeyedblond in forum Forms
    Replies: 0
    Last Post: 11-18-2005, 01:18 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