|
-
Dec 10th, 2001, 11:26 AM
#1
Thread Starter
New Member
Importing listbox text into a database
The thing i asked about in the last thread works now..
Private Sub cmdImport_Click()
Dim J As Integer
Dim ArtNr As Single
J = 1
For J = 1 To lstArt.ListCount
daBesteld.Recordset.AddNew
daBesteld.Recordset!ArtikelNr = "test"
daBesteld.Recordset!Aantal = "1000"
daBesteld.Recordset!TotPrijs = "1500"
daBesteld.Recordset!BestelDat = Date
daBesteld.Recordset!Ontvangen = "Nee"
daBesteld.Recordset.Update
Next
End Sub
This is the code that I use now.. but now i want the right values on the right place in the database..
frmLijst.lstArt.AddItem (txtArtNr.Text & vbTab & txtNaam.Text & vbTab & txtAantal.Text & vbTab & TotPrijs)
That is the code that I use to add products into the listbox.. How can I get that information back when a button is pressed, so I can import it into the database?? Please help me 'cause I'm still stuck with this thingie, and cant go on untill I've got it working right.. Thanks for your time..
-
Dec 10th, 2001, 11:39 AM
#2
Hyperactive Member
VB Code:
Dim arrSplit as Variant
Dim intUpper as Integer
Dim intLoop as Integer
arrSplit = Split (lstArt.Text,vbTab)
intUpper = Ubound(arrSplit)
daBesteld.Recordset.Edit
daBesteld.Recordset!ArtikelNr = arrSplit(0)
daBesteld.Recordset!Aantal = arrSplit(2)
daBesteld.Recordset!TotPrijs = arrSplit(3)
daBesteld.Recordset.Update
Next
As best I can see . . . My Dutch (?) is rusty (non-existent)
-
Dec 10th, 2001, 11:47 AM
#3
Thread Starter
New Member
Originally posted by gravyboy
VB Code:
Dim arrSplit as Variant
Dim intUpper as Integer
Dim intLoop as Integer
arrSplit = Split (lstArt.Text,vbTab)
intUpper = Ubound(arrSplit)
daBesteld.Recordset.Edit
daBesteld.Recordset!ArtikelNr = arrSplit(0)
daBesteld.Recordset!Aantal = arrSplit(2)
daBesteld.Recordset!TotPrijs = arrSplit(3)
daBesteld.Recordset.Update
Next
As best I can see . . . My Dutch (?) is rusty (non-existent)
Its dutch yes.. Thanks, but you are using Next.. without a loop?
-
Dec 10th, 2001, 12:16 PM
#4
Lively Member
We do something similar to what you've got here, where you put a string of data into a listbox and then need to parse back out certain fields. We had some problems when we built the string using the vbTab character. The person that wrote the code obviously didn't know about the Split function, because he parsed out the fields using Mid. Therefore, vbTab caused problems because it takes up 1 character in the VB string but when viewed, it takes up 3, and he wasn't always getting what he thought he was. We had to rework our string to use space(n) instead. As long as you do it the way that was suggested by GravyBoy, you should be fine.
Just something to keep in mind if you try to do something else with the string.
--KSW
-
Dec 10th, 2001, 12:28 PM
#5
Thread Starter
New Member
PrijsStuk = "Select I_Prijs From Artikel Where Artikelnr = " & ArtNr & ""
Isnt it possible to let PrijsStuk be the result of the query? if so, what did I do wrong?
-
Dec 10th, 2001, 12:36 PM
#6
Lively Member
PrijsStuk = "Select I_Prijs From Artikel Where Artikelnr = " & ArtNr & ""
All this statement does is assign the "Select..." string to PrijsStuk. You didn't mention the datatype of PrijsStuk, but I would assume it is a string. If you meant it to be a Recordset, then you need to execute the sql statement. If you're using ADO, it would be something like
VB Code:
PrijsStuk.Open SQLStatement, ConnectionObject
--KSW
-
Dec 10th, 2001, 03:49 PM
#7
Hyperactive Member
Sorry, ignore the Next - I just forgot to delete it . . . the split should work even with the vbTab . . . let me know if it doesn't.
You may need to use some other kind of delimiter.
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
|