+ Reply to Thread
Results 1 to 3 of 3

Use key to incerement text box from anywhere in a form

Hybrid View

chromachem Use key to incerement text... 01-26-2012, 10:45 AM
OnErrorGoto0 Re: Use key to incerement... 01-26-2012, 11:26 AM
chromachem Re: Use key to incerement... 01-26-2012, 12:50 PM
  1. #1
    Registered User
    Join Date
    01-12-2010
    Location
    Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    47

    Use key to incerement text box from anywhere in a form

    We use a form to log water samples in the lab. Each sample needs a different number of bottles. There is a text box in the form where we enter the number of labels needed for the current sample. We use the tests required for the sample to calculate the value for the text box. Sometimes bottles are broken in shipment and we need 1 or more fewer labels for the sample. Sometimes we receive an extra bottle for a sample and we need more than the calculated number of labels.


    There are two keys we never use in the form.

    OK. This I what we want to do:

    From any field, anywhere in the form, we want to use the Ctrl key to increment the value in the number of labels text box by one.
    From any field, anywhere in the form, we want to use the Alt key to decrease the value in the number of labels text box by one.

    The code below only works when the specific text box is selected.

    Private Sub txtLabID2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    If KeyAscii = 43 Then
    txtLabID2.Text = txtLabID1 + 1
    SendKeys "{BKSP}"
    End If
    End Sub

    We would like to "program" a key for the form that works anywhere within the form.

    As always, thanks for any help.

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Use key to incerement text box from anywhere in a form

    You realise you will not be able to use the Ctrl key copy/paste operations if you do this? It might be simpler if you used a click on the form itself for example? If not, you will need a class and variables of each control type declared withevents.
    Good luck.

  3. #3
    Registered User
    Join Date
    01-12-2010
    Location
    Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Use key to incerement text box from anywhere in a form

    We would be happy to use a key combination. The idea would be to limit the behavior of whatever key or key combination is selected to a specific form. On exiting the form, we would want all keys to behave as normal.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1