title: Access VBA code to insert into two different tables
body: <p>I have a user form that inserts into "user" table and "organizer" table
  when i click a button, user data gets inserted with no problem, but organizer table data doesn`t. it gives me an error saying "ms access set 1 filed to null due to type conversion failure"</p>
  
  <p>NOTE: user_id is primary key in user table and foreign key in organizer table.
  its data type is long integer.</p>
  
  <p>i would appreciate any help</p>
  
  <pre><code>Private Sub InsertSqlIntoOrgTable()
  
     Dim orgUserId As Long, sqlOrgInsertUsrId As String
  
     orgUserId = getLastUserId()
  
     sqlOrgInsertUsrId = "INSERT INTO ORGANIZER (USER_ID) VALUES ('&amp;orgUserId&amp;')"
  
     DoCmd.RunSQL sqlOrgInsertUsrId
  
  End Sub
  </code></pre>
  
  <p>This function gets the last user_id that got inserted to use in the above code to insert it into the organizer table</p>
  
  <pre><code>Private Function getLastUserId() As Long
  
      Dim lastUserId As Long
  
      getLastUserId = DMax("USER_ID", "USER")
  
      getLastUserId = lastUserId
  
  End Function
  </code></pre>
  
  <p>Edit:</p>
  
  <p>My type conversion failure error has been resolved by modifying my sql statement into</p>
  
  <pre><code> sqlOrgInsertUsrId = "INSERT INTO ORGANIZER (USER_ID) VALUES (" &amp; orgUserId &amp; ")"
  </code></pre>
  
  <p>Now i want to add "organization_name" which is taken from the same user from, into the "organizer" table.
  in the same Sub above, I added stuff for doing this, but it prompted me to inter the value (organization_name) again in a small dialogue box, then gave me another error saying "ms access set one row null due to validation rule violation"</p>
  
  <p>NOTE: i didn`t put any validation rule for the "organization_name" anywhere</p>
  
  <pre><code>Private Sub InsertSqlIntoOrgTable()
     Dim orgName As String, SqlOrgNameInsert As String
  
     orgName = txtOrgName.Value  'takes the value from text field
     SqlOrgNameInsert = "INSERT INTO ORGANIZER (ORG_NAME)     VALUES (" &amp; orgName &amp; ") "
  
     DoCmd.RunSQL SqlOrgNameInsert
  
  End Sub
  </code></pre>
  
  <p>Any help?</p>