Results 1 to 7 of 7

Thread: How to add DB fields to list and textboxes..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Unhappy How to add DB fields to list and textboxes..

    Hi

    I have to add data of a db ( db.mdb ) to a combo dropdown list ( cmbdrop ).. The table is "order" in db.mdb and field is "id"..

    So when the prog is run the list is populated with ID field.. Now when i click on a particular list item.. the corresponding values of that row of table have to show in some txtboxes.. for eg if a particular data field "buy" and "sell" are associated with the field "ID " their value should show on txtbuy.text and txtsell.text automatically when that ID is chosen..

    How can i code this???

  2. #2
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: How to add DB fields to list and textboxes..

    SQL-String
    Something like:
    VB Code:
    1. Private Sub Combo1_Click()
    2.     Set rs = New Recordset
    3.         rs.Open "SELECT * FROM TABLE WHERE ROW = '" & Combo1.Text & "'", cn, adOpenForwardOnly, adLockReadOnly
    4.  
    5.         If Not rs.EOF And Not rs.BOF Then Text1.Text = rs.Fields("Whatever").Value
    6.         rs.Close
    7. End Sub


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to add DB fields to list and textboxes..

    There is no point in bringing back every field in your table unless you are going to use every field in your table (and even then, I would list each an every field name rather than using *)

    Take what Radjesh Klauke posted, but list the fields in your SELECT and then populate your textboxes using the data from the resulting recordset as Radjesh Klauke demonstrated.

  4. #4
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: How to add DB fields to list and textboxes..

    Look at: http://www.vbforums.com/showthread.php?t=332598
    I made a small tutorial.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to add DB fields to list and textboxes..

    Since your using data bound controls, the answer is in the other thread you made.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: How to add DB fields to list and textboxes..

    Hi

    I have managed to populate the list of items in my combo box...

    But now the field "item_name" which is populating my combo list also has a msp and a shipping field corresponding to it..

    What i want to do is that when a particular Item is selected in the combolist.. the corresponding msp and shipping value should get stored in txtmsp.text and txtship.text which i can display and use later..

    please advice on code

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: How to add DB fields to list and textboxes..

    Let me explain more.. The image attached is the simple form ive created



    the DB is : db.mbd
    table : to save order : order_details
    items detials : item_info
    fields in item_info : item_name, msp, shipping

    Now I have populated the list by the following code

    Code:
    Private Sub Form_Load()
    
    ' The below is to save order
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(App.Path & "\db.mdb")
    Set rs = db.OpenRecordset("order_details", dbOpenTable)
    
    'The below is to get the item detials form another field...
    Set ws1 = DBEngine.Workspaces(0)
    Set db1 = ws1.OpenDatabase(App.Path & "\db.mdb")
    Set rs1 = db1.OpenRecordset("item_info", dbOpenTable)
    
    Do Until rs1.EOF
      cmbitem.AddItem rs1!item_name
      rs1.MoveNext
    Loop
    
    End Sub
    Now what i want to do is that when a person click on a particualr item from the list ( cmbitem ).. the MSP and Shipping txt boxes should get populated by the corresponding MSP and shipping from item_info table which is next to the item name..... HOW TO CODE THIS???

    and then when a person fills in everything.. and clicks on add order it gets saved in order_detials Table

    thanks all..

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