-
Jan 28th, 2014, 11:55 AM
#1
Thread Starter
New Member
adding multiple items to textbox and access database
First, I want to say that I am VERY new to programming. That being said, I have a few questions on an inventory program i am trying to create.
Basically, you scan in a barcode label in a textbox. Click submit button and it displays the item number in a textbox and the lot number in a different textbox. At the same time the item num and lot num get added to the database (ms access).
all of this works, but my question is how can i make this work if i want to scan in multiple barcodes? So everytime submit is clicked, I want it to keep adding to the textboxes and also keep adding to the database. I'm thinking I need a loop someone and probably an array? Any suggestions? Everything is greatly appreciated!!
Code:
'determine item number from barcode
ItemNo1 = scanTextBox.Text
fint2 = InStr(ItemNo1, "E239", CompareMethod.Text)
ItemNo1 = Mid(scanTextBox.Text, fint2 + 4, fint1 - 6)
TextBox1.Text = ItemNo1
'determine lot number from scanned barcode
LotNo1 = scanTextBox.Text
fint3 = InStr(LotNo1, "$$3", CompareMethod.Text)
LotNo1 = Microsoft.VisualBasic.Mid(scanTextBox.Text, fint3 + 9)
TextLength = Len(LotNo1)
TextBox2.Text = Microsoft.VisualBasic.Left(LotNo1, TextLength - 1)
scanTextBox.Clear()
'run sql statement
selstr = "SELECT TraceLog.Item_Number, TraceLog.Lot_Number, TraceLog.Start_Time, TraceLog.WIF "
selstr = selstr & "FROM TraceLog TraceLog "
sqltext = selstr
rs.Open(sqltext, cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
item_num = TextBox1.Text
lot_num = TextBox2.Text
'add records to database
rs.AddNew()
rs.Fields("Item_Number").Value = item_num
rs.Fields("Lot_Number").Value = lot_num
rs.Fields("Start_Time").Value = Now
rs.Fields("WIF").Value = "1"
rs.Update()
rs.Close()
cn.Close()
rs = Nothing
cn = Nothing
-
Jan 28th, 2014, 05:13 PM
#2
Re: adding multiple items to textbox and access database
You don't need a loop because you're not performing the same action multiple times without intervention. You only add one item with each submission so no loop. It would suggest using a ListBox instead of a TextBox. The TextBox is designed for one lump of text while the ListBox is designed for a list of items, which is exactly what you have.
-
Jan 28th, 2014, 05:41 PM
#3
Thread Starter
New Member
Re: adding multiple items to textbox and access database
Originally Posted by jmcilhinney
You don't need a loop because you're not performing the same action multiple times without intervention. You only add one item with each submission so no loop. It would suggest using a ListBox instead of a TextBox. The TextBox is designed for one lump of text while the ListBox is designed for a list of items, which is exactly what you have.
Thank you for the advice. i will give a listbox a try.
-
Jan 28th, 2014, 05:45 PM
#4
Re: adding multiple items to textbox and access database
By the way, your code looks like it's straight out of a VB6 app. If you're new to programming and you want to program in VB.NET then I suggest that you don't learn how to write VB6 code in .NET. Learn how to write "proper" VB.NET code. Use ADO.NET for data access and get rid of all those Mid, Left, Len, etc., calls. I would suggest that you follow the tutorial link in my signature below and work your way through that.
-
Jan 28th, 2014, 05:50 PM
#5
Thread Starter
New Member
Re: adding multiple items to textbox and access database
thank you! yes, i'm very new to programming! I appreciate your feedback and i will be checking out your link!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|