Control textbox to load data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n3wkid
    New Member
    • Jun 2014
    • 9

    Control textbox to load data

    Dear All,

    I have question about control textbox.

    example,

    I have two textbox and have placed in the form(datasheet to show all table of data).

    design layout if i use control source on the form such as the mention below

    | number | status |
    -------------------
    | 1 | ok |
    | 2 | ok |


    but now there I want to make unbound for textbox,and without source to load table.

    Code:
    ----cut of code--
    Set rs = New ADODB.Recordset
    rs.Open "select * from sample order by id", CurrentProject.Connection, adOpenStatic, adLockOptimistic
            
            Do While Not rs.EOF
                Me.text0 = rs!id
                Me.text1 = rs!status
            rs.MoveNext
            Loop
    if i run, there only one row to show, so how to create with vba for control textbox like datasheet form to show all data. thanks
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    You are only updating one record on your form, even if you have a thousand records in your table. Exactly what is the purpose of this code? Can't you achieve the same thing by using bound controls on here table?

    If you want to do what you are doing, so that you can assign values from a different table or query to your form, you must keep the test boxes bound create a string for your SELECT statement and then assign the query to the record source of the form:

    Code:
    Me.RecordSource = strSQL
    Hope this helps.

    Comment

    • n3wkid
      New Member
      • Jun 2014
      • 9

      #3
      Can we assign the value without bound in the form (assign the value with vba)?

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        Yes, you can assign the value of an unbound form in VBA, but if you have multiple records, and cycle through assigning values, it will look like it is only assigning the last value in the recordset, even though it has updated it multiple times.

        Hope that makes sense.

        Comment

        • n3wkid
          New Member
          • Jun 2014
          • 9

          #5
          sorry sir,..can you show me how to make it(code in vba)?
          i think i only need to make control textbox and assign the value after i create code for loading recordset so the form look such as datasheet.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            I'm sorry I don't understand. I think you have the tools; I don't know what you are asking for. Assign the SQL String to the Recordsource of the Form, and if the form is in data sheet view, it should work. But, the controls need to be bound.

            Comment

            • Jerry Maiapu
              Contributor
              • Feb 2010
              • 259

              #7
              Populating values of a combo box is different from bounding the value of a combo box to a table.

              You can simply populate the combo values of Number & Status from a query by creating a query and assigning the values to the combo. You basically don't need VBA to produce what you are a trying to achieve.

              Like twinnyfo said, you have all the tools you need at your disposal.

              Thanks

              Comment

              Working...