Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vba code control defaults (access 97)

    hi all
    example: in the code window, i select a control from the left drop down. let's just say that it is a text box. access defaults to "before update" as the event to start with. is there any way to change what it defaults to for any particular type of control? i don't know about you but i have used "before update" perhaps once in 2 years of programming. i am constantly using "after update" and would love if it could default to that instead. if nothing else, perhaps default to nothing at all - make you select the event yourself. any help would be appreciated

    thanks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: vba code control defaults (access 97)

    If there is already a routine for that control, it will default to that routine. Otherwise, you get them in the order MS has decided to give them to you. AFAIK there is no way to change that. Just delete the shell it drops in there for BeforeUpdate and select something else instead.

    FWIW, I use BeforeUpdate whenever I really need to validate a control before letting the user move on. In VB the equivalent event is called Validate.
    Charlotte

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: vba code control defaults (access 97)

    Like Charlotte, I also use BeforeUpdate quite a bit; and I'm sure she is just as surprised as I am that you aren't using it more. Sometimes the Order Of Events is not perfectly clear (like the Form_BeforeInsert event, for example), and you might be overlooking a valuable tool.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba code control defaults (access 97)

    thanks charlotte,
    most of the time, i just need an event to happen after a control updates. if i need to validate, i check afterwards or check when the "OK" button is pressed. if you could give me some examples of how and where you would use before update it would be appreciated. i would hate to be not using something that could help me out

    thanks

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: vba code control defaults (access 97)

    If you want to be sure that the value entered in the control is a number between 1 and 10, for example:

    Private Sub TextBox1_BeforeUpdate(Cancel As Integer)
    If Me.TextBox1 < 1 Or Me.TextBox1 > 10 Then
    MsgBox "You must enter a number between 1 and 10."
    Cancel = True
    End If
    End Sub

    This will let the user know they goofed and will keep them in the field so they can fix it. The only way out is for them to hit ESC to undo the value.

    The BeforeUpdate event of a Form is even more useful because you can test controls to see if they skipped entering a value that has to be there.

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.TextBox1) Then
    Msgbox "You must enter a value between 1 and 10."
    Cancel = True
    Me.TextBox1.Setfocus
    End If
    End Sub
    Charlotte

  6. #6
    2 Star Lounger
    Join Date
    May 2001
    Location
    indiana
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba code control defaults (access 97)

    hmm, i guess i never realized that. it is useful to check the value before it gets updated in the table as opposed to after its updated and going back to change it if its wrong. thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •