1,216
社区成员
发帖
与我相关
我的任务
分享
'楼主如果是向U8凭证表写入记录,则可以参考:
private sub command1_click()
dim ar_tmp as new adodb.recordset
dim StrSql as string
dim lngNo_Id as long '当月凭证最大编号
on error goto ErrHandle:
'开始事务
conn.begintrans
'根据凭证类别字与月份读取当月凭证最大编号
strsql=" select max(ino_id) as ino_id from GL_Accvouch where csing='记' and iperiod=9"
if ar_tmp.state<>adstatecloed then ar_tmp.close
ar_tmp.open strsql,conn,adopenkeyset,adlockreadonly
if ar_tmp.recordcount=0 then
lngNo_Id=1
else
if not isnull(ar_tmp!ino_id) then
lngNo_Id=ar_tmp!ino_id+1
else
lngNo_Id=1
end if
end if
ar_tmp.close
'写入凭证借方记录
conn.execute "insert into GL_Accvouch(csign,isignseq,iperiod,ino_id,inid,ccode,md,mc) values('记',1,9,"& lngNo_id &",1,'1001',100,0)"
'写入凭证贷方记录
conn.execute "insert into GL_Accvouch(csign,isignseq,iperiod,ino_id,inid,ccode,md,mc) values('记',1,9,"& lngNo_id &",2,'1002',0,100)"
'提交事务
conn.committrans
msgbox "保存成功!",vbokonly,"提示"
exit sub
'错误处理
ErrHandle:
'出错,回滚事务
conn.rollbakctrans
msgbox "操作失败,错误原因为:" & err.description,"提示"
exit sub
end sub