Results 1 to 7 of 7

Thread: Importing listbox text into a database

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    11

    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..

  2. #2
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    VB Code:
    1. Dim arrSplit as Variant
    2. Dim intUpper as Integer
    3. Dim intLoop as Integer
    4.  
    5.      arrSplit = Split (lstArt.Text,vbTab)
    6.      intUpper = Ubound(arrSplit)
    7.  
    8.     daBesteld.Recordset.Edit
    9.  
    10.     daBesteld.Recordset!ArtikelNr = arrSplit(0)
    11.     daBesteld.Recordset!Aantal = arrSplit(2)
    12.     daBesteld.Recordset!TotPrijs = arrSplit(3)
    13.  
    14.    daBesteld.Recordset.Update
    15.  
    16. Next

    As best I can see . . . My Dutch (?) is rusty (non-existent)
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    11
    Originally posted by gravyboy
    VB Code:
    1. Dim arrSplit as Variant
    2. Dim intUpper as Integer
    3. Dim intLoop as Integer
    4.  
    5.      arrSplit = Split (lstArt.Text,vbTab)
    6.      intUpper = Ubound(arrSplit)
    7.  
    8.     daBesteld.Recordset.Edit
    9.  
    10.     daBesteld.Recordset!ArtikelNr = arrSplit(0)
    11.     daBesteld.Recordset!Aantal = arrSplit(2)
    12.     daBesteld.Recordset!TotPrijs = arrSplit(3)
    13.  
    14.    daBesteld.Recordset.Update
    15.  
    16. Next

    As best I can see . . . My Dutch (?) is rusty (non-existent)
    Its dutch yes.. Thanks, but you are using Next.. without a loop?

  4. #4
    Lively Member
    Join Date
    Nov 2001
    Posts
    89
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    11
    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?

  6. #6
    Lively Member
    Join Date
    Nov 2001
    Posts
    89
    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:
    1. PrijsStuk.Open SQLStatement, ConnectionObject

    --KSW

  7. #7
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    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.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width