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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to make form control ignore symbols

Status
Not open for further replies.

doerfohio

Technical User
Aug 30, 2004
34
US
Our ID cards have a magnetic strip that automatically inserts % before the ID number and ? after the number like this: %255? (this is passID number 255). When the ID card is scanned into the unbound control, IDSearch, I want the control to ignore the % and ? and just read the number. Is there a way to do this?

I've tried this code on the before update event of cboIDSearch:
Code:
 Me.[cboIDSearch] = Mid(Left(Me.[cboIDSearch], Len(Me.[cboIDSearch]) - 1), 2)
But when I type in a number or the symbols and number I get the following error:
The function set to the Before Update property for this field is preventing Microsoft Access from saving the data in the field.

I also tried this:
Code:
Me.cboIDSearch = Replace(Replace(Me.PassID, "%", ""), "?", "")
And I got this error:
Invalid use of null

FYI: There's a code in the AfterUpdate event of cboIDSearch that stores the PassID and a timestamp. Otherwise, this scan is used to bring up this record at the bottom of the form.

Can you spot what I'm doing wrong?

Thanks,
Dori
 
I do not think you can do this in a Before Update event. Why not change the field as the first thing in the After Update Event?
 
you need to be changing the textbox.text property, not the textbox value itself in the before update event as the new text box value doesn't exsist at that point.

either that or do this in the after update event as remou said

--------------------
Procrastinate Now!
 
How are ya doerfohio . . .

Try your [blue]Replace function[/blue] in the [blue]AfterUpdate[/blue] event . . .

Calvin.gif
See Ya! . . . . . .
 
And what about this ?
Me!cboIDSearch = Replace(Replace(Me!PassID & "", "%", ""), "?", "")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah! I'm almost there... In the After Update event I tried:

Code:
Me.[cboIDSearch] = Mid(Left(Me.[cboIDSearch], Len(Me.[cboIDSearch]) - 1), 2)

And it worked!

However, if someone types in an ID number (without the symbols), instead of scanning it, there's a error:
"Could not locate Pass ID" then "You entered an expression that has no value"
Is there any way around this? Or should I just tell the users that is a "scan only" field.

Thanks,
Dori
 
Hi Dori!

Wrap it in an IIf function:

IIf(Left(Me.[cboIDSearch], 1) = "%", YourStuff, Me.[cboIDSearch])


hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Jeff, I know you have the answer here...but I don't know exactly how to word this. Every way I try to put "My Stuff" I have problems. Can you be more specific?
Thanks!!
 
Hi again!

Your stuff is what worked above:

Mid(Left(Me.[cboIDSearch], Len(Me.[cboIDSearch]) - 1), 2)

So you get:

Me.[cboIDSearch] = IIf(Left(Me.[cboIDSearch] = "%", Mid(Left(Me.[cboIDSearch], Len(Me.[cboIDSearch]) - 1), 2), Me.[cboIDSearch])

hth

Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
I tried that and got a sytax error. So I copied and pasted yours and got the same error. What's missing?
 
Me.[cboIDSearch] = IIf(Left(Me.[cboIDSearch][!],1)[/!] = "%", Mid(Left(Me.[cboIDSearch], Len(Me.[cboIDSearch]) - 1), 2), Me.[cboIDSearch])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV!

Had that in my original post and then typed it wrong the second time around.



Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top