Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Understanding Events

    If I have a text box on my form, and I place an event in the Change event, shouldn't the code run when the next record is selected?

    <img src=/S/bash.gif border=0 alt=bash width=35 height=39>
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Understanding Events

    Hi Drk,
    You want the OnCurrent event of the form I think - the Change event of the textbox only occurs when the text of the control changes for that particular record (unless it's an unbound control) not when the next record is selected.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Northern, California, USA
    Posts
    1,886
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Understanding Events

    Hrmph.. Why wouldn't this work then?

    Sub Form_Current()

    If AttyStateAgencyID2.Value = Null Then pgState2.Visible = False
    If AttyStateAgencyID2.Value > 1 Then pgState2.Visible = True
    If AttyStateAgencyID3.Value = Null Then pgState3.Visible = False
    If AttyStateAgencyID3.Value > 1 Then pgState3.Visible = True
    If AttyStateAgencyID4.Value = Null Then pgState4.Visible = False
    If AttyStateAgencyID4.Value > 1 Then pgState4.Visible = True

    End Sub
    <IMG SRC=http://www.wopr.com/w3tuserpics/Kel_sig.gif>
    Moderator:<font color=448800> Pix Place, Internet Explorer</font color=448800>
    <small>www.kvisions.com

  4. #4
    ravey
    Guest

    Re: Understanding Events

    Check your VBA syntax. An "If" block needs an "End If". What you really should use here is a Case block, though.

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

    Re: Understanding Events

    You only need an End If when you use a structured, multi-line statement. When it's in a single line, like this, then you don't use an End If. A select case works with a single condition tested against multiple cases. In this case, there are multiple conditions.

    Drk, part of the problem with this code was pointed out in another thread--you can't evaluate anything against Null. Anything = Null will always return False, even Null=Null. That's the first part of the problem.

    The second part depends on what this is supposed to be doing. If you're using a specific control value to set the visible property of another control, then your code will work with minor modifications. But if pgState# represents a tab page, you have a different problem. If the situation is the former, I posted code in the other thread that should work. If it's the latter, then please explain how you could be setting multiple pages to visible at the same time, which is what it looks like your code is trying to do.
    Charlotte

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

    Re: Understanding Events

    No. The change event for a control only fires when you make a change to the data in the field. And it doesn't wait until you finish typing, it happens as you type. So if you had a name field with contains "Fred", and then you started to overwrite it with "Mark", the Change event will fire after each letter you type!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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