Results 1 to 4 of 4
  1. #1
    vetabz is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jan 2017
    Location
    Philippines
    Posts
    13

    Nothing Works for Recordset in VBA


    I have this query below (and it's working, obviously nothing so complicated)

    Click image for larger version. 

Name:	a query.PNG 
Views:	19 
Size:	6.5 KB 
ID:	27257


    unfortunately nothing of the 3 works in VBA
    Code:
    Sub test()
    Dim oDB As DAO.Database
    Dim oRS As DAO.Recordset
    
    
    Set oDB = CurrentDb
    Set oRS = oDB.OpenRecordset("backup_base_staff", dbOpenDynaset) 'does not work
    Set oRS = oDB.OpenRecordset("backup_base_staff", dbOpenTable) 'does not work
    Set oRS = oDB.OpenRecordset("backup_base_staff", dbOpenSnapshot) 'does not work
    End Sub

    and I am getting this same error for all three, what am I doing wrong?

    Click image for larger version. 

Name:	invalid operation.PNG 
Views:	19 
Size:	5.5 KB 
ID:	27258

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you are trying to open a recordset which is an append (i.e. an action) query

    use

    oDB.execute "backup_base_staff",dbfailonerror

    instead

    edit: removed brackets

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    I believe a simpler code line should fire that saved query object:

    docmd.openquery "query name"

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it will, but the .execute method enables error report on the sql and access to the recordsaffected property

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

Similar Threads

  1. Replies: 1
    Last Post: 06-21-2015, 07:58 AM
  2. Replies: 4
    Last Post: 01-22-2015, 09:57 AM
  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