Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    8

    Unanswered: Object variable not set.

    Following up on a previous thread (which was solved by running RegSvr32 on a couple of DLL files)...

    This code worked under Access 2003, but now I'm getting an Object variable or With block variable not set error on the rsEnv.Open line.

    Public Sub SetEnvironmentLabel()
    Dim strSQL As String
    Dim rsEnv As ADODB.Recordset

    strSQL = "SELECT E.Name, TC.TestCaseName " & _
    "FROM Environment E, TestCase TC " & _
    "WHERE TC.EnvironmentID = E.EnvironmentID " & _
    "AND TC.TestCaseID = " & Me.cboTestCaseName.Value

    rsEnv.Open strSQL, CurrentProject.Connection

    Me.lblCurrentEnvironment.Caption = "Environment: " & rsEnv!Name

    rsEnv.Close
    Set rsEnv = Nothing
    End Sub ' SetEnvironmentLabel


    rsEnv = Nothing at that point, because the command hasn't executed yet. Since this code ran under 2003, can somebody tell me what's missing under 2007?

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    If you add "new" to the line it should work:

    Code:
    Dim rsEnv As New ADODB.Recordset

  3. #3
    Join Date
    Nov 2009
    Posts
    8
    Yes, I caught that myself just after I posted the original message. My apologies for wasting your time.

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    No problem. Maybe this thread will someone in the future as well.

Posting Permissions

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