Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Posts
    184

    Unanswered: How do I Data-bind a TextBox in Access?

    Hello I downloaded this control http://www.geocities.com/scirocco_ha/DataControl.htm

    I made a Visual Basic application using it and it works great. However I am having trouble using the same control in Access. This is what I did.

    I created the form, and droped the control on the form and inserted this code in the load event:

    ActiveXCtl5.CursorLocation = adUseClient
    ActiveXCtl5.LockType = adLockBatchOptimistic
    ActiveXCtl5.DisconnectedRecordset = True
    ActiveXCtl5.CursorType = adOpenStatic
    ActiveXCtl5.OpenRecordset "SELECT * FROM AD_Countries", "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Test.mdb;Persist Security Info=False"
    Text6.ControlSource = ActiveXCtl5.Recordset.Fields("Description").Value

    The control works as it retreives the right number of records (as shown in the record number box) and I can do searches using the find button. However I cannot see any of the results in the Text6 textbox as I am not sure how to bind it.

    The ActiveX control returns an ADO recordset, how do I bind the textbox to one of the fields in that ADO recordset?

    Thanks for any help with this.
    Attached Thumbnails Attached Thumbnails untitled.gif  
    In abundance of water only the fool is thirsty. Bob Marley.

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    Obviously the problem is with this line:

    Text6.ControlSource = ActiveXCtl5.Recordset.Fields("Description").Value

    What other variations have you tried? Have you tried this:

    Text6.ControlSource = ActiveXCtl5.Recordset.Fields("Description")

    or leave the text box unbound and on current:

    Text6 = ActiveXCtl5.Recordset.Fields("Description").Value

    You won't be able to change it, but do you want it editable anyway?

  3. #3
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: How do I Data-bind a TextBox in Access?

    Originally posted by rami.haddad
    Hello I downloaded this control http://www.geocities.com/scirocco_ha/DataControl.htm

    I made a Visual Basic application using it and it works great. However I am having trouble using the same control in Access. This is what I did.

    I created the form, and droped the control on the form and inserted this code in the load event:

    ActiveXCtl5.CursorLocation = adUseClient
    ActiveXCtl5.LockType = adLockBatchOptimistic
    ActiveXCtl5.DisconnectedRecordset = True
    ActiveXCtl5.CursorType = adOpenStatic
    ActiveXCtl5.OpenRecordset "SELECT * FROM AD_Countries", "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Test.mdb;Persist Security Info=False"
    Text6.ControlSource = ActiveXCtl5.Recordset.Fields("Description").Value

    The control works as it retreives the right number of records (as shown in the record number box) and I can do searches using the find button. However I cannot see any of the results in the Text6 textbox as I am not sure how to bind it.

    The ActiveX control returns an ADO recordset, how do I bind the textbox to one of the fields in that ADO recordset?

    Thanks for any help with this.
    You may have trouble because the forms recordset is going to be a DAO recordset. Don't know all of the implications of this but that may be an issue.
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  4. #4
    Join Date
    Jan 2004
    Posts
    184

    Re: How do I Data-bind a TextBox in Access?

    Yes exactly that is the case but you can force an ADO recordset like this:

    Set rsTEST = New ADODB.Recordset
    rsTEST.Open "SELECT * FROM AD_Countries", CurrentProject.Connection, adOpenStatic, adLockBatchOptimistic
    Set Me.Recordset = rsTEST 'This forces the ADO recordset

    This is where I am now

    Set ActiveXCtl5.Recordset = Me.Recordset
    Text6.ControlSource = "Description"

    The control works as it retreives the right number of records (as shown in the record number box) and I can do searches using the find button. However I cannot see any of the results in the Text6 textbox as I am not sure how to bind it.

    Is there a way to bind the textbox to an ADO recordset and NOT bind it to the Form Recordset? (without using the Microsoft Data control)
    In abundance of water only the fool is thirsty. Bob Marley.

  5. #5
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    ADO is still new and missing many features that dao already has. Why do you need it bound? Can you not just assign the value to an unbound field so it will show:

    Text6 = ActiveXCtl5.Recordset.Fields("Description").Value

  6. #6
    Join Date
    Jan 2004
    Posts
    184
    Thank you Sudbury for your help.

    I need it bound as the user will cycle through the records, make changes, deletes etc...

    I need to bind it to an ADO recordset as that is the latest technology and also that is what the control returns. If I can bind the textbox to the ADO recordset, I will be able to add new, delete, save etc... without any further coding.

    In VB this is done easily like this:

    Set txtbox.DataSource = ADORecordset
    txtAuthorID.DataField = "Description"

    But I am having trouble doing the same in Access.
    In abundance of water only the fool is thirsty. Bob Marley.

  7. #7
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    As of Access XP, ADO could not be used to update on a form or recordset. If you need to save changes, then you may have to stick with old technology until the new technology matures.

Posting Permissions

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