Results 1 to 4 of 4
  1. #1
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71

    if-then statement in vba

    Hello!

    I have a form called restaurantinfo with a save button on it, and some simple vba behind it. A text box called savedtext appears when it is clicked to show the user that their info has been saved:

    Private Sub savebutton_Click()
    DoCmd.Save
    Me.savedtext.Visible = True
    End Sub




    How can I make an (if-then) statement that says that if any further changes are made to the info (pulling from table restaurantinfo) on the form, then Me.savedtext.Visible = False ?

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Two things:

    1. DoCmd.Save has nothing to do with records. It has to do with the saving of DESIGN CHANGES to the form. If you want to run a save, use

    If Me.Dirty Then Me.Dirty = False

    which will ONLY try to save if something has been changed on the form.

    2. You would need to test in the form's Dirty event to see if anything changes.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Oh, and the Form's On Dirty event will ONLY fire if a change is made to a control which is bound to a field on a bound form. Unbound controls and unbound forms will not fire the On Dirty event because there is no record source that is changing.

    If you have unbound controls you would need to check in their before update event if the .OldValue is different from the current .Value.

  4. #4
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Thank you! I didn't know about the Dirty event before.

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

Similar Threads

  1. If Statement Help
    By vennies83 in forum Queries
    Replies: 1
    Last Post: 06-09-2011, 03:50 PM
  2. for each statement in vba
    By tuyo in forum Access
    Replies: 0
    Last Post: 03-22-2011, 05:42 PM
  3. iff Statement
    By tkandy in forum Access
    Replies: 0
    Last Post: 03-20-2011, 02:31 PM
  4. if statement
    By sirlosi in forum Queries
    Replies: 4
    Last Post: 03-07-2011, 11:26 AM
  5. SQL like statement?
    By Cojack in forum Queries
    Replies: 4
    Last Post: 09-21-2010, 04:45 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