Results 1 to 10 of 10

Thread: ADO controls: how to bind data to the textbox

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39

    data control binding??????????

    Hi all
    I want to know if I can achieve the followings when using an ADO control on the form:

    Dim dbSe As Connection
    Dim recSet2 As Recordset

    Set dbSe = New Connection
    dbSe.Provider = "msdasql"
    dbSe.ConnectionString = "dsn=Xtreme sample" _
    & "data;uid=sa;pwd=;"

    dbSe.Open

    Set recSet2 = New Recordset
    recSet2.Open "select * from customer", dbSe, _
    & adOpenDynamic, adLockPessimistic

    txtFields.DataField = "Customer ID"
    Set txtFields.DataSource = adoPrimaryRS

    I got a ADO control on the form called 'adoRecset' which refers to a DSN and then for its recordset to a table call 'customer'.


    sm

  2. #2
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281
    Try setting the textbox this way:


    txtFields.text = adoRecset.customerID



  3. #3

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39
    No the porblem is that it complains that the object is not set and i am having problem 'opening' the 'adorecset' remember its an ado control on the form.

    how do i
    open it without binding any object directly becasue as soon as you bind any object ie bind a text box to the data control then it is opened,referenced and instantiated. but how do i get it to work just using source code.

    sm

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39
    ANY REPLY APPRECIATED!
    sm

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    so you want to bind a textbox to a recordset object, and NOT a data control?

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39
    actually Clunietp I want to bind it to data control binding it to a recordset object is already done see my code above.

    Maybe if we forget the textbox and just say once you have assigned a DSN and a table to your ADO control then :
    How do i using source code open the ado data control connection so its recordset is set and ready to be used?

    sm

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Originally posted by sultan

    How do i using source code open the ado data control connection so its recordset is set and ready to be used?

    huh? the recordset is set and ready to be used when your form loads and the data control populates itself....

    I must be missing your ultimate goal here....

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39
    Thanks Clunietp

    1) Drag one ADO data control onto form.

    2) Drag one textbox onto form.

    3) Set the ADO control's ADODC property and choose an appropriate DSN for its ODBC data source name then choose a table for its record source.

    4) Leave all the properties of the text box default at design time.

    Now using source code bind the text box to the ado data control.

    ie
    txtbox1.DataField = "Customer ID"
    Set txtbox1.DataSource = adoDataControl
    sm

  9. #9
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    OK

    I put this into form_load:

    Code:
    Private Sub Form_Load()
        
        Text1.DataField = "CustomerID"
        Set Text1.DataSource = Me.Adodc1
        
    End Sub
    It works fine, the textbox is bound to the data control

    I set the connection string of the data control and put in a recordsource

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 1999
    Posts
    39
    Many thanks Clunietp
    The silly thing works for me as well but I can almost swear the same combination of code failed everytime I tried it in the past!!

    WHAT IF I don't want to use any of the controls including the text box how can you access the record set that i want using the ADO Control.
    sm

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