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

formating using VBA, if then statements

Status
Not open for further replies.

jwalt

Programmer
Dec 7, 2001
3
US
ok kids.....

I need to format a control (i.e. tblepartnumbers) for two different formats depending on the beginning digit to the left. The formats might be 6-666-66
or 7-777-777

Using a scanner to retrieve the bar code and place it in the control i want to use VBA to write code in the Properties/On Click to format the data and store it.

My thought which of course doesn't run is to use the first digit as the "if" and wildcards as the remaining digits:

if me.tblepartnumbers = 6?????
then me.tblepartnumbers = 6-???-??
elseif me.tblepartnumbers = 7??????
then me.tblepartnumbers = 7-???-???

Please advise, thanks in advance, john

 
Try this...

If Left(Me.tblepartnumbers, 1) = "6" Then
s = Format(Me.tblepartnumbers, "#-###-##")
ElseIf Left(Me.tblepartnumbers, 1) = "7" Then
s = Format(Me.tblepartnumbers, "#-###-###")
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top