Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PreviousControl (access97/SR2)

    I'm struggling to understand what I really want to do, in terms of the programming. Here's the situation:

    I have an Access97 form with four telephone number text boxes. A text box might contain the string "252-6677", and I want to prefix the number with an area code such as "905-".

    I thought of creating a Command Button "cmd905" and writing code to prefix the existing contents of the active control with the string "905-", so, I thought, one command button with a caption "905", and I'd click in one of the four text boxes, click the comamnd button, and all would be well.

    Of course, at the time I click on cmd905, THAT control is active, and I can't obtain, or set, the contents of the previously active control, assumed to be one of the four text boxes.

    What's the solution to this programming problem?

    1) Whenever I click in one of the four text boxes I could store the control's identity in a global variable, and access that global variable from cmd905; that seems a clunky solution.

    2) Make use of an apparently non-existant "PreviousControl" property of the Screen.


    Thoughts?


    To make it double confusing, I'm upgrading my contacts list, and where a telephone number has only seven digits, it ought to be upgraded to EITHER 905- or 416-, since we split this part of The Frozen North into two area codes. I'm contemplating a choice of two command buttons - cmd905 and cmd416 - for each of the four fields (work phone, home phone, alternate phone, fax phone)

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PreviousControl (access97/SR2)

    I would use a separate control (possibly a drop down list) in front of each list box to contain the area code.
    Legare Coleman

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

    Re: PreviousControl (access97/SR2)

    Lo and behold! The Screen object has a property named - TADAA - PreviousControl. So - provided you do some checking to avoid havoc if the user hasn't clicked one of the telephone number text boxes before clicking the command button, you can use Screen.PreviousControl.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PreviousControl (access97/SR2)

    >The Screen object has a property named - TADAA - PreviousContro

    Hans, if you ever get re-incarnated, it should be as a lovable labrador, then you can become a guide dog for the blind.


    Or as they say in Access/VBA "There be none so blind as they that cannot C" (grin!)


    How did I miss that? Perhaps because I still feel unfamiliar with Access/VBA objects and haven't taken the time to explore them more fully.

    I'l live with the risk of wreaking havoc for now, since i am the only user of the system ......


    <pre>Private Sub cmd905_Click()
    On Error GoTo Err_cmd905_Click

    Dim ctlCurrentControl As Control

    Set ctlCurrentControl = Screen.PreviousControl

    Dim strPhone As String
    strPhone = ctlCurrentControl.OldValue
    strPhone = "905-" & strPhone
    ctlCurrentControl = strPhone

    Exit_cmd905_Click:
    Exit Sub

    Err_cmd905_Click:
    MsgBox Err.Description
    Resume Exit_cmd905_Click

    End Sub

    </pre>


  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PreviousControl (access97/SR2)

    > I would use a separate control

    Thanks Legare , but I forgot to mention that I'm running out of real estate on the form!

    I like the idea of a drop-down list, especially if I ever get beyond two area-codes.

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PreviousControl (access97/SR2)

    Well, if you have the real estate for the current textbox to hold the area code, then that text box made smaller by the width of an area code should provide the real estate needed.
    Legare Coleman

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

    Re: PreviousControl (access97/SR2)

    Chris, was there a reason for posting this is VB/VBA or is it just habit? You're better off posting all your Access questions in the Access forum since the object model is so different from the other Office apps and the forms and controls are entirely diferent.
    Charlotte

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PreviousControl (access97/SR2)

    > text box made smaller by the width of an area code

    Legare, I stated the problem in a poor fashion.

    Each of the four textboxes (is that the correct plural?), target of all our enthusiasm, has to be wide enough to accommodate a ten-digit number.

    A box that currently contains "252-6677" is space-filled. When I prefix "905-", the text box will need to accommodate "905-252-6677", so the real estate has to be set aside.

    I figure that a command button, maybe only 8x8 pixels, is a deal smaller than a drop-down listbox.

    I don't see that I can REDUCE the size of the telephone text boxes; did you see that I could?

    We may be discussing different things here, I know (smile!)

Posting Permissions

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