0

Data getting inserting successful . some case if fields data Empty , Null or other issue execution silently ignoring without any error or debug

Dim RS As Object
Dim RSS As Object
Dim Con As Object
Set RS = CreateObject("ADODB.RecordSet")
Set Con = CreateObject("ADODB.connection")
sql = "insert into wfile( testname,optz,subject,type,direction, question, opt1,  opt2, ) values('" & testname & "','5','" & subject & "','" & type1 & "','" & direction1 & "','" & question & "','" & opt1 & "','" & opt2 & "')"
'MsgBox sql
Set RS = Con.Execute(sql) 

Here How can throw error if unable to insert data

braX
  • 11,506
  • 5
  • 20
  • 33
  • When you paste the completed `sql` into Access it should give you a more specific error. Keep in mind you only need quotes around text field values, not numeric ones. – braX Nov 22 '21 at 05:40
  • @braX sir can you please example it "completed sql into Access" now the data inserting fine .some case only not inserting .. need to debug or display msg when can't getting insert – Gajendran Nov 22 '21 at 05:53
  • `Debug.Print sql` will tell you what the value of `sql` is. You can then copy/paste that into an MS Access query that you create using that text. Then you try to run it. Is that what you are asking? – braX Nov 22 '21 at 05:55
  • yes sir but only need to show if not getting inserted – Gajendran Nov 22 '21 at 06:10
  • My suggestion was just for debugging. If it happens "only sometimes" then you need to figure out why so that you can fix it. The only way to detect if it was inserted would be to re-read the database to look for it. – braX Nov 22 '21 at 06:16
  • Also: Try removing this last trailing comma - `opt2, ) values` - There should not be a comma after the `opt2` – braX Nov 22 '21 at 07:36
  • thank you @braX i got idea that default value in database Null to accept all data – Gajendran Nov 22 '21 at 09:33

0 Answers0