|
-
Oct 31st, 2008, 04:36 PM
#1
Thread Starter
New Member
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.
-
Oct 31st, 2008, 04:58 PM
#2
Re: Form Editing Question

I've moved your thread here which is the place to ask VBA questions.
-
Oct 31st, 2008, 10:49 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|