Results 1 to 9 of 9
  1. #1
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159

    VBA Save Button

    Hi all,

    I have a save button that I created using the access command button wizard.

    However, I want to add some validation to my form which occurs when this button is clicked.

    I just want to make sure various fields are filled in. I know how to validate - I just don't know how to add said validation to a macro button.

    In other words - how do I save a record using code instead of macros OR how do I add code to a macro?

    Look forward to hearing YOUR wisdom.

    Cheers!


    Richardo

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  3. #3
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Thanks Mr. Orange for the prompt reply.

    I will have a look.

    I love this forum - it is awesome - and so are the people on it.

    Luuvin it!!!

    Saved me putting me head through the monitor many times!

    Mr. Blue

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  5. #5
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Hey thanks - I will have a gander at that!

  6. #6
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    K, so I read the link and added this to the before update event of the control I was trying to validate - and nothing happened when I hit my macro created save button. I.E: No msgbox even though I left the field cboBoxes blank!!

    Private Sub cboBoxes_BeforeUpdate(Cancel As Integer)

    If IsNull(Me.cboBoxes) Then
    MsgBox "You must select a box"
    Me.cboBoxes.SetFocus
    Exit Sub
    End If

    Way wait....tis on a subform -> Would that have an impact???

    Tankee sar, thankee kindly.........

    End Sub

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I don't work with macros. The link I sent dealt with macros and vba code.

  8. #8
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Hmmm...seems few experienced people do.... I guess there's more control with VBA........Have a nice day! ....As they say in the states ;-)

  9. #9
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    Well, I found what I was looking for. Think I will stay away from automated controls like macros in future.

    It's just so time consuming to find what you want when you want it.

    Mr. Orange - what do you think is the best way to learn VBA? Plow through books or just to spend time searching online when you need to do something specific?

    For anyone interested - this worked for me:

    Private Sub save_Click()

    If IsNull(Me.cboBoxes) Then
    MsgBox "You must select a box"
    Me.cboBoxes.SetFocus

    Cancel = True
    Exit Sub
    End If

    DoCmd.RunCommand acCmdSaveRecord

    End Sub

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

Similar Threads

  1. do NOT save record on close (x button)
    By benjammin in forum Forms
    Replies: 12
    Last Post: 03-15-2013, 02:54 AM
  2. Save button
    By tia in forum Forms
    Replies: 19
    Last Post: 01-10-2012, 06:15 AM
  3. Save button say syntax error
    By venu_resoju in forum Forms
    Replies: 6
    Last Post: 02-14-2011, 02:52 AM
  4. Help Require (Macro Save button )?????
    By aligahk06 in forum Access
    Replies: 1
    Last Post: 04-18-2010, 08:38 AM
  5. Save to PDF Button?
    By SpeedyApocalypse in forum Forms
    Replies: 2
    Last Post: 04-10-2010, 06:06 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