Results 1 to 3 of 3

Thread: Form Editing Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    1

    Form Editing Question

    I am using VBA to assist our company with MicroSoft Projects. I've designed a form to help keep track of quantites as opposed to hours. Its
    got 3 labels and 3 corresponding text boxes, Task Name, Estimated Quantity,
    and Completed Quantity. The labels are; txtqtype, txtqest, txtqcom
    respectively. There is an ok and cancel button as well.

    Im not a regualr programmer but I was able to figure out how to make it do
    what I want it to do. I figured the formatting would be the easy stuff. I was
    wrong. It is supposed to read the information in the Task Name field in
    Projects, truncate the part of the string in parenthesis and print the
    remainder into the text box txtqtype. For txtQest it reads the string and
    truncates everything outside of the parenthesis the prints the value to the
    textbox txtqest.

    I want that string to be displayed when I start the form up and the cursor
    to defualt on the bottom textbox txtqcom. This is what I have as far as
    reading and displaying the string.

    Private Sub txtQtype_Enter()
    Dim Qtype, Qvar, Qstop

    Qvar = ActiveCell

    If Qvar = Empty Then
    txtQtype.Locked = False
    Else
    txtQtype.Locked = True
    txtQtype.BackColor = RGB(180, 180, 180)
    End If

    Qstop = InStr(1, Qvar, "(", vbTextCompare)
    If Qstop = 0 Then
    Qtype = Qvar
    txtQtype.Text = Qtype
    Else
    Qtype = Left(Qvar, Qstop - 1)
    txtQtype.MaxLength = Qstop - 1
    txtQtype.Text = Qtype

    End If


    End Sub


    I dont even know if I should be using the Enter event. But its the only
    thing I can do to get even close to what I want to happen. If someone could
    help me out with this I'd appriciate it. Sorry its not commented. Also I'd
    like to know how to make pressing the Enter button when in a textbox function
    the same as clicking OK.

  2. #2

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Form Editing Question

    to set the focus to a specific textbox you can either in design mode set the tabstop proerty to 0
    or in the form initialise event use txtqcom.activate

    if you want the code you posted to take effect as soon as you load the form, try the form initialise event

    you should avoid, if possible, reference to activecell, but provide the full address to the cell

    setting th maxlength of textbox only stops the user entering more characters. but does not limit length of text entered by code, you would need to cut the string like
    txtQtype.Text = left(Qtype, instr(qtype, "(") - 1)
    and to get txt inside parenthesis
    Code:
    pos =  instr(somestring, "(")
    txtQest.text = mid(somestring ,pos +1, instr(pos +1, somestring, ")") - pos -1)
    of course in either example i the string does not contain the parenthesis then an error would occur
    Also I'd like to know how to make pressing the Enter button when in a textbox function the same as clicking OK.
    check out the enterkeybehvior property of the text box or the default property of the OK button
    Last edited by westconn1; Oct 31st, 2008 at 10:55 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width