Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have the right idea but VBA is quite a bit different from PHP. You can't use variables inside strings with first exiting the string, concatenating the variable, and then starting the string again.</p> <p>Where you would typically use an array called arrDev or arrVSys, we use a DAO Recordset or ADO Recordset object inside MS Access.</p> <p><strong>Updated answer to reflect the information you gave:</strong></p> <pre class="lang-vb prettyprint-override"><code>Dim db As DAO.Database Dim sSQL as String Dim arrDEV As DAO.Recordset, Dim arrVSYS as DAO.Recordset Set db = OpenDatabase("C:\SomeDatabase.accdb") sSQL = "SELECT ID, ClusterID FROM DeviceTable WHERE Distribution &lt;&gt; 'Public'" Set arrDEV = db.Open(sSQL) If Not (arrDEV.EOF and arrDEV.BOF) Then arrDEV.movefirst Do Until arrDEV.eof = True sSQL = "SELECT ID FROM VirtualSystemTable WHERE DeviceID = " &amp; arrDEV("ID") &amp; _ " OR ClusterID = " &amp; arrDEV("ClusterID") Set arrVSYS = CurrentDb.Open(sSQl) sSQL = "DELETE FROM InterfaceTable WHERE DeviceID = " &amp; arrDEV("ID") &amp; _ " OR ClusterID = " &amp; arrDEV("ClusterID") &amp; " OR VirtualSystemID = " &amp; arrVSYS("ID") CurrentDb.Execute sSQl, dbFailOnError sSQL = "DELETE FROM VirtualSystemTable WHERE DeviceID = " &amp; arrDEV("ID") &amp; " OR ClusterID = " &amp; arrDEV("ClusterID") CurrentDb.Execute sSQl, dbFailOnError sSQL = "DELETE FROM ClusterTable WHERE ID = " &amp; arrDEV("ClusterID") CurrentDb.Execute sSQl, dbFailOnError arrVSYS.Close arrDEV.MoveNext Loop End If 'Cleanup Set arrVSYS = Nothing arrDEV.Close Set arrDEV = Nothing db.close Set db = Nothing </code></pre> <p>The code is untested and could have some errors. The only thing I didn't plan for was having more than one record in arrVSYS. If that recordset will have multiple records then you'll need yet another loop.</p> <p>As you can see, you don't need to use ADO to access another Access database. But if the "outside" database is something other than Access then yes, you would need to use ADO.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload