Results 1 to 2 of 2
  1. #1
    mdpepper1 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5

    create an onclick event for a button created by vba

    I've created a form using vba and I have used the createControl function to add a button to the form.

    I want to include code in the button creation which specifies what I would like to happen when the button is pressed (run an sql insert )

    How can I achieve this?

    button code:

    Code:
     
         Set ctlNew = CreateControl(frm.Name, acCommandButton, , , "newButton", 500, 500)
        ' Set control's caption.
        ctlNew.Caption = "New Command Button"
        
        With ctlNew
        .Name = "niceNewButton"
    
    
        End With


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why are you using VBA to create objects and controls? Why not use the designers?

    Just use the designer to drag a button control to the form. Then in the Click event property for the button, select [Event Procedure], double click the ellipses (...), to go to the procedure in the VBA editor. Type code.

    Why do you need an sql INSERT? Is the form bound to data and data entry controls bound to fields of the form's RecordSource? If so, just type data into the controls, entries go direct to table. Close form and record is committed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. OLEunbound onclick event
    By thangasiva in forum Forms
    Replies: 1
    Last Post: 03-26-2015, 10:55 AM
  2. OnClick Event submit and clear
    By Desstro in forum Forms
    Replies: 1
    Last Post: 01-12-2011, 09:42 AM
  3. Onclick event
    By tmcrouse in forum Forms
    Replies: 3
    Last Post: 09-18-2010, 01:10 PM
  4. OLEunbound onclick event
    By thangasiva in forum Access
    Replies: 1
    Last Post: 06-27-2010, 01:49 PM
  5. OnClick event
    By HotTomales in forum Forms
    Replies: 1
    Last Post: 12-24-2009, 08:10 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