Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    11

    Unanswered: Filling records to an unbound form

    Hello all,

    Does anyone know what the code is to fill a form's recordset?

    I have an unbound form at the moment, and I would like to populate the form's recordset by copying data from an ADODB.recordset.

    Code:
    Private Sub Command1_Click()
        Dim rst As New ADODB.Recordset
        
        rst.ActiveConnection = CurrentProject.Connection
        rst.CursorType = adOpenKeyset
        
        ' Retrieve ID's that start with 1
        rst.Open "SELECT * FROM tData WHERE left(ID,1)=1"
        
        Dim frm As Form
        Set frm = Forms![fTest]![fTest_Sub].Form
       
        ' Populate form textboxes with recordset data    
        With frm
            Do Until rst.EOF
                 !ID = rst("ID")
                 !PartNumber = rst("PartNumber")
                 !Description = rst("Description")
            
            --- [ Need code here that will insert new row for next loop ] ---
    
                 rst.MoveNext
            Loop
        End With
        
        rst.Close
        Set rst = Nothing
        
    End Sub
    I'm using this approach because this will act as a filter to allow a user to retrieve a specificied set of records.

    Thanks in advance for your help.
    Last edited by STC; 09-13-03 at 13:45.

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    are you making your life more complicated than necessary?

    try:

    dim strSQL as string
    strSQL = "SELECT * FROM tData WHERE left(ID,1)=1"
    Forms![fTest]![fTest_Sub].Form.recordsource = strSQL

    izy

Posting Permissions

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