Results 1 to 6 of 6

Thread: Error: set datPrimaryRS = New ADODB.Recordset

  1. #1

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Error: set datPrimaryRS = New ADODB.Recordset

    Im getting an error on the Line
    VB Code:
    1. Set datPrimaryRS = New ADODB.Recordset
    The error reads "Variable Not Defined" but I've used this same code on 10 or so different projects and NEVER had a problem before...

    What gives?

    VB Code:
    1. Dim sConnect As String
    2.     Dim sSQL As String
    3.     Dim dfwConn As ADODB.Connection
    4.    
    5.     ' set strings
    6.     sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Referral\Referral Rebuild\referrals.mdb;Persist Security Info=False"
    7.     sSQL = "select DrID, SpecialistType, SpecialistLastName, SpecialistFirstName, Address, Fax, Phone, Remarks from Specialists where SpecialistLastName like '" & Text8.Text & "'"
    8.  
    9.    ' open connection
    10.     Set dfwConn = New ADODB.Connection
    11.     dfwConn.Open sConnect
    12.    
    13.     ' create a recordset using the provided collection
    14.     Set datPrimaryRS = New ADODB.Recordset
    15.     datPrimaryRS.CursorLocation = adUseClient
    16.     datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
    17.  
    18.     Set MSHFlexGrid1.DataSource = datPrimaryRS
    19.     MSHFlexGrid1.Refresh
    20.    
    21.     Text9.Text = datPrimaryRS![SpecialistFirstName]
    22.     Text10.Text = datPrimaryRS![SpecialistType]
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  2. #2

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Resolved Re: Error: set datPrimaryRS = New ADODB.Recordset [RESOLVED]

    I dont know why this changed all of the sudden, but I just added
    VB Code:
    1. Dim datPrimaryRs As New ADODB.Recordset
    and it seems to be working fine now.
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Error: set datPrimaryRS = New ADODB.Recordset

    When you DIM - do not use the NEW.

    When you SET, then use the NEW.

    Did you used to have this as a global/module level declaration?

  4. #4
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: Error: set datPrimaryRS = New ADODB.Recordset

    szlamany:

    Out of curiosity, what are the disadvantages of using new in the Dim statement and taking care of that there, eliminating the need for the set statement?
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Error: set datPrimaryRS = New ADODB.Recordset

    From one of my favorite books - WROX publications - ADO 2.6 Programmers Reference.

    Code:
    Dim objRS as New ADODB.RecordSet
    This creates the object reference immediately, but the object is not instantiated until the first property or method is called. This means that the object is not instantiated when declared but later in the code - which can lead to debugging problems. A better solution is the use this method:

    Code:
    Dim objRS as ADODB.RecordSet
    Set objRS = New ADODB.Recordset
    I've seen postings here on the forums where checking the object = Nothing didn't work properly unless the second method was used. Seemed to me to be in reference to .NextRecordSet

  6. #6
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: Error: set datPrimaryRS = New ADODB.Recordset

    Gotcha. Thanks.
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

Posting Permissions

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



Click Here to Expand Forum to Full Width