Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Args (97)

    I wonder if there is a quick answer to the following:

    I have this procedure that I run to clear text boxes on a dblClick event.

    Dim obj As TextBox
    Set obj = Me.ActiveControl
    With obj
    .Value = ""
    .SelStart = 0
    .SetFocus
    End With

    If i wanted to put it in a separate module to call from any form, how would i pass the activecontrol argument? would i use a string or control variable?

    would it be something like

    sub Clear (obj)
    With obj
    .Value = ""
    .SelStart = 0
    .SetFocus
    End With

    and then be called by

    dim obj as control
    Set obj = Me.ActiveControl
    call clear(obj)

    or is there an easier way?
    Thanks,

    pmatz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing Args (97)

    The best way is to pass a control argument. You could use the control name, but it would be more work. Instead of

    dim obj as control
    Set obj = Me.ActiveControl
    call clear(obj)

    you could use

    Clear Me.ActiveControl

    By the way, I don't understand your Clear procedure.
    - Why do you set its value to ""? I would use Null instead.
    - Once the control is blank, you don't need to set SelStart to 0 any more - it will be 0 automatically.
    - Why do you need to set focus to the control that is already the active control?
    - If you would call Clear with a control that is *not* the active control, SelStart would cause an error.

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Args (97)

    Clear me.activecontrol makes sense, and works - thanks.

    Well, i was doing the selstart =0, setfocus stuff because i am trying to get the following behaviour.

    to clear the textbox and await user input, the textbox is for inputting date info and the input mask is 00/00/00.

    i want the box to be set to ' __/__/__' and be at the start so the user can type straight back in.

    for some reason this works on some forms but not others. It works on unbound texztboxes, but where data is input into bound fields the box is just cleared, but no input mask is brought back up as in the unbound fields.

    thanks for the pointers. Null is ok to use then? i will try that. but i dont know how to get the text box input mask back. I will try to setfocus on something else and then bring focus back to it.

    cheers
    Thanks,

    pmatz

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing Args (97)

    Ah, I didn't know you were using an input mask.

    Where are you calling this code? I just tried it (without the SetFocus) on both a bound and an unbound control, and SelStart = 0 displayed the input mask in both cases.

  5. #5
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Args (97)

    Hi, I think i see why .. i am calling it from a double click event on the bound forms, its the dbl click that the prob. if i call iot from the click (as in the unbound form) then its fine.

    hmmm.

    another Q that you may know how to do...

    can i change a forms view from datasheet to form from within VB, so when it is a subform on one parent it is datasheet, but then on another parent it is form?

    i know the code, but get the error it can only be changed in design mode.

    <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>
    Thanks,

    pmatz

  6. #6
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Args (97)

    Private Sub Rtrnd_DblClick(Cancel As Integer)
    Cancel = 1
    Call P1.dtClr(Me.ActiveControl)
    End Sub

    the cancel =1 ( i thought i would try it) solves it! I imagine it performs the same kind of thing as Keycode= 0 on a keydown event.
    Thanks,

    pmatz

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing Args (97)

    Setting Cancel to True (or in fact any value other than 0 = False) will cancel the default action of the event. There are other event procedures with a Cancel event too, BeforeUpdate is an example. In all those cases, Cancel is False initially, but you as programmer can set it to True to cancel the event.

Posting Permissions

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