Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if Input Mask Field Empty

Status
Not open for further replies.

Ktx7ca

IS-IT--Management
Apr 5, 2008
88
CA
HI

I have an unbound Field with a phone number input mask

I need to check and see if the field is empty so I can set the cusor postion to the begining. if the field has any thing in it then I don't want to set the cursor postion

I have tried various adaptations of the following code with no luck

I'm using the onclick event at this time

if trim(me.phonelookup & "") = "" then
me.phonelookup.selstart =1
endif


if I remove the input mask it works fine

any Ideas?


 
Strange, that exact code works for me as expected... [ponder]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi HarleyQuinn

Did you have the phone input mask in place at the time?

mine works if i don't use the mask.

and I agree very strange
 
Yep, Input mask was applied at the time of testing.

What do you get if you put this:
Code:
MsgBox Me.phonelookup
in the click event of the textbox?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Sorry, that meant to read:
Code:
Debug.Print Me.phonelookup
The code I posted before will throw an Invalid use of Null error if the value of the textbox is what I expect it to be.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I get Invalid use of null error 94
 
Oppsp sorry with the Debug I get no error
 
Right, so it's returning Null as expected, I take it that the code go into your If statement?

When you step through and get to the line
Code:
me.phonelookup.selstart =1
mouse over the SelStart property and that should tell you the current value.

So does the code appear to just not do anything when it runs?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
How are ya Ktx7ca . . .

I believe the starting position is 0, not one (a one character offset). Also, [blue]the field has to have the focus[/blue] to read/change the property. Try:
Code:
[blue]me.phonelookup.SelStart = 0[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi AceMan,

I think with the phone number input mask the SelStart should work with both 1 and 0, but if that turns out to be the problem (as I didn't ask the OP what the actually didn't work with the posted code [sad]) I'll have to make sure I ask in future [wink].

If it doesn't solve it I'll ask, what exactly isn't working with the code you posted when the input mask is applied?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
OK lets see

Using Debug I get a null value when clicking on the field. I'm using the selstart as 1 so the cursor sits in the first empty space and not on the bracket, But i have tried it at 0 with the same result.

As to answer your question (pretty relivent one at that
) about what dos'nt work. if the field any data in it it still sets the cursor to postion 1



 
If I do this using the input mastk
Code:
Private Sub Command6_Click()
  If Trim(Me.phoneNum & " ") = "" Then
    Me.phoneNum.SetFocus
    Me.phoneNum.SelStart = 1
  Else
    Me.phoneNum.SetFocus
    Me.phoneNum.SelStart = Len(Me.phoneNum.Text)
  End If
End Sub

It puts it at the end or at the first position.

or simply this works
Me.phoneNum2.SetFocus
Me.phoneNum2.SelStart = Len(phoneNum2.Text) + 1

you need to add a space in your trim statement
& " " not & ""

In the else part of the check you can do something else beside such as setting the focus to another control
 
Is that any data that doesn't completely match the input mask, e.g. half a phone number?

I mean, in my testing, if you had a full phone number in it worked correctly (but as expected I couldn't leave the field once I'd entered it until I entered a string matching the mask).

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
HI Harley

That is correct any data like half a phone number. I dont want the selstart to be set . I only want it to be set if the field is blank.



 
I have a feeling that this has something to do with how the value of the textbox with the input mask is held in memory, in my testing, unless the input mask criteria is satisfied (using the test on the click event of the textbox anyway) the value is always Null so will always enter the If statement.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
But doesn't checking the length of the .text vice the .value property solve that issue?
 
Not really, the way it was works if there's either nothing of something that fully matches the input mask, if not you can't exit the textbox. With those behaviours they both work. It's the Click event of the textbox cauising problems I think (I hope that made some sembelence of sense [wink])

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I can not replicate the OP error. I get it to go to the first space if if there is nothing in the field, and either have it ignore or go to the last space if there is a partial in the field. The OP claims there are partials which I assumed meant they where entered in another table or form without an input mask or imported into the db. By testing that approach the code still works except a partial fills from the right of the text box.
 
HI everyone

OK I understand the input mask takes control and does not assign a value to my field untill it's criteria has been met. Unfortunatly that makes sense

Thanks everyone for all the Help. I'll shall find another way to do what I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top