Ignore the letter P?

ASharp

New member
Local time
Today, 11:41
Joined
Nov 23, 2009
Messages
4
Hey I have been lurking here for awhile, learning a lot. You guys have been really helpful on several things.


Anyhow, I have this form where I am using a barcode scanner to input data. Do to a recent change to the barcode all new barcodes will start with a letter P. I want to be able to scan the rest of the barcode into my form, but not input the P.

Is there a way to disregard the first character only when its a "P"?

Not sure if that makes sense or not...

I am looking for simplest way to do this, as my skills in access are very low.

Thanks
 
It depends exactly how your code is working at the moment, but the principle looks something like this:

Code:
Dim BC As String
 
BC = [[I]your barcode in full][/I]
 
If Left(BC,1) = "P" Then BC = Mid(BC,2)
 
[I][your field][/I] = BC
 
I think understand everything, except
BC = [your barcode in full]

Any chance you could be more specific on what info i need there? Im sure im missing something simple...

sorry bout being a noob..
 
You need to replace [your barcode in full] with the actual name of the textbox on your form that holds your scanned barcode.
 
cool.. thanks, that helped some. not getting an error now.

however still getting that darn P..

seems like such a simple request to be so darn annoying... lol

I just dont know nearly enough about coding...
 
Where are you placing this code? We could probably benefit from seeing your code!
 
I am doing it BeforeUpdate.

the feild i want to update is called Partnumber in the table that i am updating with the form. In the form the text box name is the same thing... Maybe thats whats confusing me.

I am posting below what the code looks like... im sure the Partnumber parts are wrong, but im still really confused about why exactly.

Private Function Partnumber_BeforeUpdate(Cancel As Integer)
Dim BC As String

BC = Partnumber

If Left(BC, 1) = "P" Then BC = Mid(BC, 2)

[Partnumber] = BC
End Function


thanks for any help..
 
First off, you're apparently entering your event code freehand without selecting the control and then going thru the Properties sheet, which is a dangerous practice, unless you are very, very experienced. This is obvious because your code is in a Function, which won't work as you're trying!

Private Function Partnumber_BeforeUpdate(Cancel As Integer)

This function will not fire after data is entered in the textbox. It will only fire if explicitly called.

On the other hand,

Private Sub Partnumber_BeforeUpdate(Cancel As Integer)

which is the Sub that Access generates when you select BeforeUpdate from the Properties Sheet, will fire when data is entered/edited in the textbox.

At any rate, the BeforeUpdate event is the wrong choice for this task. You cannot change the data in the BeforeUpdate event like you're trying to do, or Access will throw an error. You shoud be using the AfterUpdate event of the textbox, like this:

Code:
Private Sub PartNumber_AfterUpdate()
 Dim BC As String

 BC = Me.PartNumber

  If Left(BC, 1) = "P" Then BC = Mid(BC, 2)

    Me.PartNumber = BC
   
  End If

End Sub

This code works just fine, but could be tightened up to simply:

Code:
Private Sub PartNumber_AfterUpdate()
 
If Left(Me.PartNumber, 1) = "P" Then 
  Me.PartNumber = Mid(Me.PartNumber, 2)
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom