您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



紧急求助


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


紧急求助
发表于:2008-01-14 14:34:37 楼主
进行数据添加,
执行下列代码出错:“显示数据错误--91”

option   explicit

dim   rsfield_rec_hc   as   recordset
dim   updownpross   as   boolean

private   sub   commandadd_rec_click()
       
        dim   tablesname   as   string
        on   error   goto   errhand
        rsfield_rec_hc.update
        if   focus_node.key   <>   ""   then
                tablesname   =   focus_node.key
        else
                tablesname   =   focus_node.tag
        end   if
        showdataaddlist   tablesname
       
        textfield.text   =   listfield.list(0)
        listfield.selected(0)   =   true
        textvalue.text   =   ""
        textvalue.setfocus
        rsfield_rec_hc.addnew
        init_add_rec
        exit   sub
errhand:
        msgbox   "显示新增数据有误!——"   &   error,   vbcritical,   "错误"
end   sub

private   sub   commandok_click()
'on   error   goto   errhand
                updownpross   =   true
                if   textvalue   =   ""   then   exit   sub
                rsfield_rec_hc.fields(selectfield.max   -   selectfield.value)   =   textvalue
                if   selectfield.value   <>   1   then
                        selectfield.value   =   selectfield.value   -   1
                        textvalue.text   =   ""
                        textvalue.setfocus
                else
                        commandadd_rec.setfocus
                end   if
                listfield.selected(selectfield.max   -   selectfield.value)   =   true
                textfield.text   =   listfield.list(selectfield.max   -   selectfield.value)
                updownpross   =   false
                exit   sub
errhand:
        msgbox   "填写属性值格式错误!"   &   error,   vbsystemmodal,   "警告"
end   sub

private   sub   form_load()
        updownpross   =   false
end   sub

private   sub   form_lostfocus()
on   error   resume   next
        rsfield_rec_hc.close
        set   rsfield_rec_hc   =   nothing
        'init_add_rec
end   sub


private   sub   form_unload(cancel   as   integer)
        control_formview(3)   =   true
        mainform.mainform_statusbar.panels(5).bevel   =   sbrraised
end   sub

private   sub   listfield_click()
        dim   indexlistclick   as   integer
        dim   itemindex   as   integer
       
        if   rsfield_rec_hc   is   nothing   then   exit   sub
        if   updownpross   =   true   then   exit   sub
        itemindex   =   listfield.listindex
        indexlistclick   =   listfield.listcount   -   itemindex
        textfield.text   =   listfield.list(itemindex)
        if   isnull(rsfield_rec_hc.fields(itemindex))   =   true   then
                textvalue   =   ""
        else
                textvalue   =   rsfield_rec_hc.fields(itemindex).value
        end   if
        selectfield.value   =   indexlistclick
        mainform.mainform_statusbar.panels(2).text   =   cint(indexlistclick)
end   sub

private   sub   selectfield_downclick()
'on   error   goto   errhand
        updownpross   =   true
        if   selectfield.value   <>   0   then
                listfield.selected(selectfield.max   -   selectfield.value)   =   true
                textfield.text   =   listfield.list(selectfield.max   -   selectfield.value)
        end   if
        if   isnull(rsfield_rec_hc.fields(selectfield.max   -   selectfield.value))   =   true   then
                textvalue   =   ""
        else
                textvalue   =   rsfield_rec_hc.fields(selectfield.max   -   selectfield.value)
        end   if
        mainform.mainform_statusbar.panels(2).text   =   cint(selectfield.value)
        updownpross   =   false
errhand:
       
end   sub

private   sub   selectfield_upclick()
'on   error   goto   errhand
        updownpross   =   true
        if   selectfield.value   <>   0   then
                listfield.selected(selectfield.max   -   selectfield.value)   =   true
                textfield.text   =   listfield.list(selectfield.max   -   selectfield.value)
        end   if
        if   isnull(rsfield_rec_hc.fields(selectfield.max   -   selectfield.value))   =   true   then
                textvalue   =   ""
        else
                textvalue   =   rsfield_rec_hc.fields(selectfield.max   -   selectfield.value)
        end   if
        mainform.mainform_statusbar.panels(2).text   =   cint(selectfield.value)
        updownpross   =   false
errhand:
       
end   sub

private   sub   textvalue_gotfocus()
        dim   tablesname   as   string
on   error   goto   endhnd
        if   focus_node.key   <>   ""   then
                tablesname   =   focus_node.key
        else
                tablesname   =   focus_node.tag
        end   if
        set   rsfield_rec_hc   =   dbhc.openrecordset(tablesname)
        rsfield_rec_hc.addnew
endhnd:
end   sub

private   sub   textvalue_keypress(keyascii   as   integer)
        if   keyascii   =   13   then
                commandok_click
        end   if
end   sub

发表于:2008-01-14 18:34:321楼 得分:0
这样试试

textvalue       =       rsfield_rec_hc.fields(val(selectfield.max       -       selectfield.value))  
发表于:2008-01-15 10:26:382楼 得分:0
运行了提示“实时错误3021   无当前记录”

调试得到
private       sub       listfield_click()  
                dim       indexlistclick       as       integer  
                dim       itemindex       as       integer  
               
                if       rsfield_rec_hc       is       nothing       then       exit       sub  
                if       updownpross       =       true       then       exit       sub  
                itemindex       =       listfield.listindex  
                indexlistclick       =       listfield.listcount       -       itemindex  
                textfield.text       =       listfield.list(itemindex)  
                if       isnull(rsfield_rec_hc.fields(itemindex))       =       true       then  
                                textvalue       =       ""  
                else  
                                textvalue       =       rsfield_rec_hc.fields(itemindex).value  
                end       if  
                selectfield.value       =       indexlistclick  
                mainform.mainform_statusbar.panels(2).text       =       cint(indexlistclick)  
end       sub  
有问题
发表于:2008-01-15 10:34:583楼 得分:0
进行记录添加只是增加了第一个和最后一个记录,中间的都没加进来。


快速检索

最新资讯
热门点击