excel-vba nested error handling -


i wrote vba-code inserting data mysql-db , save time i've thought make execute multiple "insert" 1 connection db i'm worried possible errors in insert command so, in case of error, want execute queries once @ time.

this makes possible execute commands without errors but, if there error, again , i'll need handle it.

to thought code below but, looking similar, didn't find ... maybe bad idea? there better way this?

this idea:

for = 1 100     '...do      'first error handling activation     on error goto errhandle1      'reset sql string     sqlstr = ""      'loop making sql string multiple insert     ii = 1 50         '...example instructions:         sqlstr = sqlstr & "insert mytab (myfield) values ('" & ii / & "'); "     next ii     'execute insert @ 1 time     rs.open sqlstr, cn, adopenstatic  gonext: on error goto 0 next  exit sub  'primary error handling errhandle1: 'no instrutions here 'i use resume reset error resume handle1 handle1:  'i try again insert loop connection db every query 'second error handling activation on error goto errhandle2 ii = 1 50     'string 1 insert     sqlstr = "insert mytab (myfield) values ('" & ii / & "'); "     'single query execution     rs.open sqlstr, cn, adopenstatic next ii 'back base code goto gonext  'secondary error handling errhandle2: msgbox err & " - " & error(err) resume next 

i recommend placing error handling routines on level of error (with if false separator normal course). avoid goto 0 in case of fundamental errors, use resources.

on error goto errhandleri = 1 100 '...do     ii =1 50     on error goto errhandlerii         'do other thing     if false errhandlerii:     'do error handling stuff     end if     next ii if false errhandleri: 'code, e.g. paint whole line blue end if next 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -