ERROR 3137 (1 Viewer)

mhakim

Member
Local time
Today, 14:54
Joined
Jan 25, 2021
Messages
72
here is the code
trying to insert two line in same time
by the way one line is working but when trying to add another line it give error 3137


"INSERT INTO test_table_transactions (T_Account_Number ,T_acc_sub_number,branch_id)" & _
" VALUES ('" & Account_Num & "','" & Thirdparty_id & "', '" & branch_id & "'), " & _
" ('" & Account_Num_2 & "',NULL, '" & branch_id_2 & "') ; "
 

cheekybuddha

AWF VIP
Local time
Today, 12:54
Joined
Jul 21, 2014
Messages
2,280
Not possible in Access using the VALUES form of the INSERT statement.

You will need to use 2 INSERT statements unless you are able to convert to:

INSERT INTO test_table_transactions (T_Account_Number ,T_acc_sub_number,branch_id)
SELECT .... 2 records FROM ....
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:54
Joined
Feb 28, 2001
Messages
27,186
Just for clarity: The INSERT INTO ... VALUES syntax is ALWAYS a single-record insertion. One record per SQL activation. David's suggested response uses the other syntax: INSERT INTO ... SELECT .... FROM - which allows as many insertions as were implied in the SELECT.
 

mhakim

Member
Local time
Today, 14:54
Joined
Jan 25, 2021
Messages
72
Just for clarity: The INSERT INTO ... VALUES syntax is ALWAYS a single-record insertion. One record per SQL activation. David's suggested response uses the other syntax: INSERT INTO ... SELECT .... FROM - which allows as many insertions as were implied in the SELECT.
i have seach online and google bard i found that you can do same as i do

but how i will use select the data i want to record on a form not on table
 

Attachments

  • insert into multiple lines.png
    insert into multiple lines.png
    74.6 KB · Views: 50

cheekybuddha

AWF VIP
Local time
Today, 12:54
Joined
Jul 21, 2014
Messages
2,280
Just for clarity: The INSERT INTO ... VALUES syntax is ALWAYS a single-record insertion
Not always!
MySQL, Oracle, Postgres (I think) allow the syntax used by the OP where you can use multiple comma delimited sets of VALUES

Edited to add: I think also possible in SQLServer too since SQLServer 2008
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 12:54
Joined
Jul 21, 2014
Messages
2,280
Just shows that you really need to double-check AI results which are presented so definitively.

It's the new equivalent of "Well it must be true because I read it on the internet"! :ROFLMAO:
 

mhakim

Member
Local time
Today, 14:54
Joined
Jan 25, 2021
Messages
72
Then, in Access, you must just insert one record at a time.
thanks dear
but i have to search more because i need to but at least two lines like accounting entries a line for debit and a line for credit

so if you have clear idea how to use select with insert into to put two lines
 

cheekybuddha

AWF VIP
Local time
Today, 12:54
Joined
Jul 21, 2014
Messages
2,280
Code:
With CurrentDb
  strSQL = "INSERT INTO test_table_transactions (T_Account_Number ,T_acc_sub_number,branch_id)" & _
           " VALUES ('" & Account_Num & "','" & Thirdparty_id & "', '" & branch_id & "');"
  .Execute strSQL, dbFailOnError
  If .RecordsAffected = 1 Then
    strSQL = "INSERT INTO test_table_transactions (T_Account_Number ,T_acc_sub_number,branch_id)" & _
             " VALUES ('" & Account_Num_2 & "',NULL, '" & branch_id_2 & "') ; "
    .Execute strSQL, dbFailOnError
  End If
End With
Or you can use a transaction to wrap the two statements.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:54
Joined
Feb 28, 2001
Messages
27,186
For absolute clarity, do it one insert at a time. Like David is suggesting. Is it SO hard to just repeat the INSERT INTO ... VALUES statement once for each of two records?

For the record, I was unaware that external SQL engines allowed that. Access does not. When I worked with ORACLE, it wasn't with an Access FE.
 

Users who are viewing this thread

Top Bottom