Results 1 to 5 of 5

Thread: [RESOLVED] MS Access to SQL Linked tables connection

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] MS Access to SQL Linked tables connection

    I am getting the following error on this pretty basic line of code hope someone can help.
    Object Variable or With block variable not set
    'MS Access VBA Code

    VB Code:
    1. Private Sub Form_Load()
    2. Dim rs As Recordset
    3. Dim cnn As Connection
    4. [U]cnn = CurrentProject.Connection[/U]
    5. rs.Open "SELECT * from Employees", cnn, , , adCmdText
    6. Me.lstEmpStates.RowSourceType = ValueList
    7. While Not rs.BOF And Not rs.EOF
    8. 'Me.lstEmpStates.Additem
    9. rs.MoveNextWend
    10. End Sub

  2. #2
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: MS Access to SQL Linked tables connection

    Change the line to
    VB Code:
    1. set cnn = CurrentProject.Connection

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: MS Access to SQL Linked tables connection

    Thanks that has taken me past that error, I now get the same error on the next line..
    rs.Open "SELECT * from Employees", cnn, , , adCmdText

  4. #4
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: MS Access to SQL Linked tables connection

    Quote Originally Posted by FishGuy
    Thanks that has taken me past that error, I now get the same error on the next line..
    rs.Open "SELECT * from Employees", cnn, , , adCmdText
    The problem is that rs is not an instance of an object yet. Theis can be done with the New keyword when you declare the variable
    VB Code:
    1. dim rs as new recordset
    or later by using the Set keyword
    VB Code:
    1. Set rs=New recordset

  5. #5

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: MS Access to SQL Linked tables connection

    Thanks

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