title: Invalid object name, but object is clearly valid
body: <p>I am attempting to run some SQL queries in MS Access, but a certain query is behaving very oddly and is throwing an error which I believe is obscuring the actual problem. Here is the query in question:</p>
  
  <pre><code>objCmd.CommandText = "DECLARE @equipID varchar(50) DECLARE d 
  CURSOR FOR SELECT equipmentID FROM [EWOM].[dbo].[equipment] OPEN d" 
  &amp; _
  " FETCH NEXT FROM d INTO @equipID WHILE @@FETCH_STATUS = 0 BEGIN" &amp; 
  _
  " UPDATE [EWOM].[dbo].[Equipment] SET eqNum = 
  REPLACE(REPLACE(equipmentID, ' ', ''), '.', '') WHERE equipmentID = 
  @equipID" &amp; _
  " FETCH NEXT FROM d INTO @equipID End Close d DEALLOCATE d"
  </code></pre>
  
  <p>And this throws the error </p>
  
  <blockquote>
    <p>Invalid Object Name 'EWOM.dbo.Equipment'</p>
  </blockquote>
  
  <p>However, I've used several queries using this exact same object that have worked perfectly fine. Here's an example of a query that is fully operational:</p>
  
  <pre><code>objCmd.CommandText = "TRUNCATE TABLE [EWOM].[dbo].[Equipment]" &amp; _
  " INSERT INTO [EWOM].[dbo].[Equipment] (equipmentID, make, model, 
  equipmentName, status)" &amp; _
  " SELECT Equipment, Manufacturer, Model, Description, Status" &amp; _
  " FROM [Vp].[dbo].[bEMEM]"
  </code></pre>
  
  <p>What baffles me is that the first query I showed works fine in SQL Server Management Studio, but it failed when I transitioned it to Access. Is the true problem coming from a syntax issue with the first query? Any help would be appreciated.</p>
  
  <p>Here is the full code for a working query:</p>
  
  <pre><code>Dim Cnn As ADODB.Connection
  Dim rst As ADODB.Recordset
  Dim objCmd As New ADODB.Command
  
  Set Cnn = New ADODB.Connection
  Set rst = New ADODB.Recordset
  
  Cnn.Open "DBName", "username", "password"
  objCmd.ActiveConnection = Cnn
  
  objCmd.CommandText = "TRUNCATE TABLE [EWOM].[dbo].[Equipment]" &amp; _
  " INSERT INTO [EWOM].[dbo].[Equipment] (equipmentID, make, model, 
  equipmentName, status)" &amp; _
  " SELECT Equipment, Manufacturer, Model, Description, Status" &amp; _
  " FROM [Vp].[dbo].[bEMEM] WHERE EMGroup = 20"
  objCmd.CommandType = adCmdText
  
  Set rst = objCmd.Execute
  MsgBox "Update successful."
  
  Cnn.close
  Set Cnn = Nothing
  Set rst = Nothing
  </code></pre>
  
  <p>When the objCmd.commandText is changed to the first query I posted, it fails. All of my other queries work using this method.</p>