title: Insert Userform data into Access table using excel vba
body: <p>I'm currently making a simple inventory system application using Excel VBA. I have a userform to get the input and I would like to save the import data into a few Microsoft Access tables. </p>
  
  <p>I am trying to pull the data from the userform and enter it into the access table when the user hits enter. When I run this code, a new record is made with the table ID but the two records I am trying to import are left blank. </p>
  
  <pre><code>    Public Sub AddDatabaseEntry()
  
        'Initialize all variables
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        Dim stDB As String, stSQL As String, stProvider As String
        Dim orderNum As String
        Dim orderDate As String
  
        orderNum = txtOrderNum
        orderDate = txtDate
  
  
        stDB = "Data Source= " &amp; ThisWorkbook.Path &amp; "\obsDatabase.accdb"
        stProvider = "Microsoft.ACE.OLEDB.12.0"
  
  
        'Opening connection to database
        With cn
  
            .ConnectionString = stDB
            .Provider = stProvider
            .Open
  
        End With
  
       'SQL Statement of what I want from the database
        stSQL = "INSERT INTO Orders (OrderNumber, OrderDate) " &amp; _
                "Values ('" &amp; orderNum &amp; "', '" &amp; orderDate &amp; "')"
  
        Set rs = cn.Execute(stSQL)
  
  
        'Looping through the records I pulled and inserting the data into the comboBox
  
        cn.Close
        Set rs = Nothing
        Set cn = Nothing
  
      End Sub
  
      Private Sub btnAdd_Click()
  
        AddProduct
        AddDatabaseEntry
  
      End Sub
  </code></pre>