title: Adding a new record with VBA
body: <p>I have a form in which one of the ComboBoxes lists all the documents of a given project. The user should select one and after pressing a button, and if present in Table <code>Dessins</code>it opens a second form showing that record. If it is not present in that table, I want to add it in.</p>
  
  <p>One of my collegues told me all I had to do was to execute an SQL query with VBA. What I have so far is this:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>    Dim rsDessin As DAO.Recordset
      Dim strContrat As String
      Dim strProjet As String
      Dim strDessin As String
      Dim sqlquery As String
  
    'I think these next 3 lines are unimportant. I set a first query to get information I need from another table
  
      strDessin = Me.Combo_Dessin
      strProjet = Me.Combo_Projet
      sqlquery = "SELECT [Projet HNA] FROM [Projets] WHERE [Projet AHNS] = '" &amp; strProjet &amp; "'"
  
      Set rsDessin = CurrentDb.OpenRecordset(sqlquery)
  
      If Not rsDessin.RecordCount &gt; 0 Then 'If not present I want to add it 
          strContrat = rsDessin![Projet HNA]
          sqlquery = "INSERT INTO Feuilles ([AHNS], [Contrat], [No Projet]) VALUES (strDessin, strContrat, strDessin)"
          'Not sure what to do with this query or how to make sure it worked.
      End If
  
   'Checking my variables
      Debug.Print strProjet
      Debug.Print strContrat
      Debug.Print strDessin
  
   'By here I'd like to have inserted my new record.
  
      rsDessin.Close
      Set rsDessin = Nothing
  </code></pre>
  
  <p>I also read online that i could achieve a similar result with something like this:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Set R = CurrentDb.OpenRecordset("SELECT * FROM [Dessins]")
  R.AddNew
  R![Contrat] = strContrat
  R![Projet] = strProjet
  R![AHNS] = strDessin
  R.Update
  R.Close
  Set R = Nothing
  DoCmd.Close
  </code></pre>
  
  <p>Is one way better than the other? In the case where my INSERT INTO query is better, what should I do to execute it?</p>