Connecting Tech Pros Worldwide Help | Site Map

Object Variable or With Block Variable Not Set

smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#1: Jul 28 '09
Expand|Select|Wrap|Line Numbers
  1. Dim cnnADO      As New ADODB.Connection
  2. Dim rstData     As New ADODB.Recordset
  3. Dim strCustomer As String
  4. Dim strSQL      As String
  5. Dim strFileName As String
  6.  
  7. On Error Resume Next
  8.  
  9.     'Set up the connection
  10.     With cnnADO
  11.         .ConnectionString = "Provider=SQLOLEDB.1;" & _
  12.                             "Password=;" & _
  13.                             "Persist Security Info=True;" & _
  14.                             "User ID=sa;" & _
  15.                             "Initial Catalog=C:\Program Files\Microsoft Visual Studio\VB98\Nwind;" & _
  16.                             "Data Source=MyServer"
  17.         .Open
  18.     End With
  19.  
In above code when debugging found that after .Open cnnADO is set equal to the string "Provider=....MyServer". But as soon as control passes End With, cnnADO is equal to "<Object Variable or With Block Variable Not Set.>".

What is the cause please help me.
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,497
#2: Jul 28 '09

re: Object Variable or With Block Variable Not Set


check if you have included proper library (from references)
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#3: Jul 29 '09

re: Object Variable or With Block Variable Not Set


Thanks changed reference from MSADO 2.6 Library to MSADO 2.8 Library. Now it works.
Reply