Results 1 to 3 of 3
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Recordset from a Form

    Hi,

    I want to get the Recordset in a Form. I get Error #13 (Type mismatch) on the command:

    Set rst = Me.Recordset

    Can someone help me what I am doing wrong. The form is active. I added som code do doublecheck that.
    Code:
    Private Sub cmdMoveUp_Click()
        Dim rst As ADODB.Recordset
        Dim fld As Field
        
        'Just for test to show that form is active
        Debug.Print Me.txtSkill.Value
        
        Set rst = Me.Recordset               'Here I get an error
        For Each fld In rst.Fields
            Debug.Print fld.Name
        Next fld
    End Sub
    Click image for larger version. 

Name:	Capture.PNG 
Views:	12 
Size:	17.3 KB 
ID:	26142

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Use the query the form is using,then create a new recordset.

    set rst =currentdb.openrecordset("qsFormQuery")

  3. #3
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Thanks,

    I tested to change ADODB.Recordset to only Recordset in declaration. Then my original code worked.

    Code:
    Private Sub cmdMoveUp_Click()
        Dim rst As Recordset
        Dim fld As Field
    
        Set rst = Me.Recordset
        For Each fld In rst.Fields
            Debug.Print fld.Name
        Next fld
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 11-28-2015, 09:58 PM
  2. Replies: 4
    Last Post: 05-20-2014, 12:45 PM
  3. Replies: 6
    Last Post: 12-03-2013, 11:14 PM
  4. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums