Store Part of Entry

A

AHopper

I posted this question as one of several questions in
Tables & Database Design, however, I think this has more
to do with a text box event so I am posting it here.

I have a barcode with the following format:
C 108900 P 000516338

The barcode and will be scanned into a text box, however
I only want to store the last 9 digits that are greater
than 0, in this case 516338. The field that will store
this is set to Number, Double.

How can I set up the text box to only store the part of
the entry I want?

Thank you for your help

Allan
 
A

AHopper

Jim,
The text box is called "UniqueLabel"
Do I place this code in one of the events like Before
Update, After Update?

This is only a sample code. The format will always be the
same - Letter, space, 6 digits, space, letter, space, 9
digits.
How would I make it generic so it would apply to any code
as it is scanned in?

After thinking more about this entry form, I realized
that it is possible for users to enter the number without
scanning it. If they do and the number is 9 digits or
less I want the entry to be allowed.

Thank you for your support and help
Allan
 
R

Rick B

You need to put the scanned (full) number in an unbound text field. Then
use the code mentioned to take the right 9 digits from that field and place
them into the bound field where you wish to store the truncated data.

Rick B


Jim,
The text box is called "UniqueLabel"
Do I place this code in one of the events like Before
Update, After Update?

This is only a sample code. The format will always be the
same - Letter, space, 6 digits, space, letter, space, 9
digits.
How would I make it generic so it would apply to any code
as it is scanned in?

After thinking more about this entry form, I realized
that it is possible for users to enter the number without
scanning it. If they do and the number is 9 digits or
less I want the entry to be allowed.

Thank you for your support and help
Allan
 
A

AHopper

Rick
I have been able to populate the text from the unbound
text box after update event as you suggested. However, I
don't know how to make the code CLng(Right("C 108900 P
000516338",9)) generic.
I always get 516338 and am not able to scan other bar
codes.

Thanks
Allan
 
J

Jim Allensworth

Use the After Update event to process the scan. This textbox should be
unbound and would send the processed result to the *field* in the
RecordSource. Also, since human entry is allowed (you almost have to
allow this), you will need to do error checking.

Check for length of input as well as numeric characters.
Maybe something like ...

Private Sub txtUniqueLabel_AfterUpdate()
If Len(Me.txtUniqueLabel & "") = 0 Then Exit Sub
If Len(Me.txtUniqueLabel) & "" > 9 Then
MsgBox "Entry error! Try again."
Me.txtUniqueLabel = Null
Exit Sub
End If
'Check for numeric chars only.
If Not (Me.txtUniqueLabel Like "*[!0-9]*") = False Then
MsgBox "Entry error! Try again."
Me.txtUniqueLabel = Null
Exit Sub
End If

'Put it in the RecordSource
Me.UniqueLabel = CLng(Right(Me.txtUniqueLabel, 9))
End Sub

The above code assumes the textbox txtUniqueLabel is unbound. Also you
would need to reset the focus back to txtUniqueLabel when the value
iset to null - use the Got Focus event of the subsequent control

Private Sub txtBox_GotFocus()
If IsNull(Me.txtUniqueLabel) Then Me.txtUniqueLabel.SetFocus
End Sub

- Jim
 
A

AHopper

Jim, Rick,
I have been experimenting and have been able to populate
the text box by declaring a variable in the After Update
event and then replacing the number in your suggestion
with the variable. Not certain this is the right or best
way but it is working.

Thanks
Allan
-----Original Message-----
Rick
I have been able to populate the text from the unbound
text box after update event as you suggested. However, I
don't know how to make the code CLng(Right("C 108900 P
000516338",9)) generic.
I always get 516338 and am not able to scan other bar
codes.

Thanks
Allan
 
J

Jim Allensworth

A string variable should be fine. It doesn't look like you have looked
at the additional code I posted yet. In that I just reference the
textbox, but a variable set to the textbox would work also. Note that
I also addressed some other issues related to user typed entries. You
might want to take a look at those.

- Jim

Jim, Rick,
I have been experimenting and have been able to populate
the text box by declaring a variable in the After Update
event and then replacing the number in your suggestion
with the variable. Not certain this is the right or best
way but it is working.

Thanks
Allan
 
A

AHopper

Jim,
I didn't see your post, until after I had sent my reply.
It seems my network is slow on receiving the updates. I
like your code and will see if I can make it work.
Thank you very much for your time and help.

Allan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top