Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA in Access 2010 - Run-time Error 430

Posted on 2013-12-06
9
Medium Priority
?
1,173 Views
Last Modified: 2013-12-06
I’m getting a Run-time error '430': Class does not support Automation or does not support expected interface" on this line of code
Set Me.lstResults.Recordset = rs

Open in new window

or this
Set Me![frmM_SearchForDocumentsSubForm].Form.Recordset = rs

Open in new window

. I am trying to get the ADO Recordset based on a SQL stored procedure to appear in an unbound Listbox or Subform of an Access form. I’m on Win 7 Machine using Access 2010 connecting to SQL Server 2008:

On_Click event:

Private Sub cmdRun_Click()
'On Error Resume Next

    Dim strSQL As String

    'Stored procedure + parameters called from form
    strSQL = "Exec sqlsp_searchalltables " & Me.txtTables & _
       ", " & "'%" & Me.txtSearchTerm & "%'"

    OpenMyRecordset rs, strSQL

    'debug - view procedure
    Me.lblQuery.Caption = strSQL
    Me.Repaint

    Set Me.lstResults.Recordset = rs
    'or this
    'Set Me![frmM_SearchForDocumentsSubForm].Form.Recordset = rs
End Sub

Open in new window


I found some solutions for this error on the web and tried all of them to no avail. Most suggested checking the references which I did and verified.

I am able to successfully connect to the SQL server and have the results display in both a Listbox and Subform when I use DAO Querydef and a passthrough query or if I use this .listbox method:

With Me.lstResults
    Do
       strItem = rs.Fields("CLIENT_ID").Value
       .AddItem strItem
       rs.MoveNext
    Loop Until rs.EOF
End With

Open in new window


I would prefer not to use the DAO method because I found I need the coding flexibility of ADO especially with connecting to multiple Recordsets in SQL. Thoughts?
0
Comment
Question by:Darlyne Pitt
  • 4
  • 3
  • 2
9 Comments
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39702061
Where are you declaring the rs object?
0
 
LVL 1

Author Comment

by:Darlyne Pitt
ID: 39702078
In a separate module:

Public Function OpenMyRecordset(rs As ADODB.Recordset, strSQL As String, Optional rrCursor As rrCursorType, Optional rrLock As rrLockType, Optional bolClientSide As Boolean) As ADODB.Recordset

    If con.STATE = adStateClosed Then
        con.ConnectionString = "ODBC;Driver={SQL Server};Server=vnysql;DSN=RecordsMgmt_SQLDB;UID=DMP;Trusted_Connection=Yes;DATABASE=RecordsManagementDB;"
        con.Open
    End If

    Set rs = New ADODB.Recordset
    With rs
        .ActiveConnection = con
        If bolClientSide Then
            .CursorLocation = adUseClient
        Else
            .CursorLocation = adUseServer
        End If
        .CursorType = IIf((rrCursor = 0), adOpenStatic, rrCursor)
        .LockType = IIf((rrLock = 0), adLockReadOnly, rrLock)
        .Open strSQL
        If .EOF And .BOF Then
            NoRecords = True
            Exit Function
        End If
    End With
    
End Function

Open in new window

0
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 2000 total points
ID: 39702093
Try setting the cursor type to adOpenDynamic and LockType to adLockOptimistic. Just a thought?? Otherwise, I hope someone else has a better idea for you.

Good luck!

ab
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 66

Expert Comment

by:Jim Horn
ID: 39702104
>Where are you declaring the rs object?
>In a separate module:
I don't see a 'Dim rs as ...' line in that function, which means it's being declared somewhere else, likely by the calling code block.

If you intend on that rs being available everywhere in your app, then in the top declaration section of any code module instead of Dim use..
Global rs as Recordset ' DAO. or ADODB., your call

Open in new window

If you intend on rs being an indifidual thing, then in the code block that calls the function use this
Global rs as Recordset ' DAO. or ADODB., your call

Open in new window

0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39702127
>when I use DAO Querydef and a passthrough query
Just for kicks and giggles, when you locate the 'Dim rs as...' line eyeball whether it is DAO.Recordset, ADODB.Recordset, or just rs.

If just rs, in any code window do a Tools:References and see whether DAO or ADODB is checked, and if so which is higher.   Reason I ask is because Access will interpret 'just rs' as whichever one is higher in the References dialog.
0
 
LVL 1

Author Comment

by:Darlyne Pitt
ID: 39702164
Okay, I think we're getting somewhere.  I did as @aebea suggested and changed the cursor type and the lock type and I'm no longer getting the Run Time error.  But what's happening now is that I'm getting  "run time error 7965: the object you entered is not a valid recordset property".  @jimhorn - I do have a global declaration in my module for rs.  Looks like this:

Option Compare Database
Option Explicit

Global con As New ADODB.Connection
Global rs As ADODB.Recordset
Global NoRecords As Boolean

Open in new window


My Access references

Access References
0
 
LVL 1

Author Comment

by:Darlyne Pitt
ID: 39702178
I forgot to mention that the new error is on the same line of code as the previous error:  
Set Me.lstResults.Recordset = rs

Open in new window

0
 
LVL 1

Author Comment

by:Darlyne Pitt
ID: 39702347
I was able to get rid of the latest runtime error by removing the IF..THEN..ELSE statement referencing the .CursorLocation in my public function. Now it only read .CursorLocation = adUseClient. Viola, it now works perfectly! Thanks for all your help.
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39702391
Glad you're all squared away. Have a good weekend!

ab
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question