| 发表于:2007-04-16 15:58:066楼 得分:0 |
我所有的代码 包括查询那部分的 option explicit dim strsql as string dim i, j, k as integer dim xlapp as variant dim xlbook as variant dim xlsheet as variant private sub cmnexcel_click() set xlapp = createobject( "excel.application ") set xlbook = xlapp.workbooks.add set xlsheet = xlbook.worksheets(1) xlapp.visible = true on error resume next if err.number <> 0 then set xlapp = createobject( "excel.application ") set xlbook = xlapp.workbooks.add set xlsheet = xlbook.activesheet xlsheet.cells.copyfromrecordset rsqrecord xlsheet.rows(1).insert for k = 1 to dgrecord.columns.count xlsheet.cells(1, k) = dgrecord.columns(k - 1).caption next k end sub private sub cmnquery_click() strsql = "select * from bgsb where " '//给定义好的字符变量赋予sql语句 " '//判断单选框中时,判断办公设备单位单选框选中时 if optdanwei.value = true then if trim(txbgdanwei.text) = " " then msgbox "请输入查询的单位 ", vbexclamation + vbokonly, "查询失败 " exit sub end if strsql = strsql & " 单位 = ' " & trim(txbgdanwei.text) & " ' " ' //判断消防名称单选框选中时 elseif optname = true then if trim(txbgname.text) = " " then msgbox "请输入的办公设备名称 ", vbexclamation + vbokonly, "查询失败 " exit sub end if strsql = strsql & " 名称 = ' " & trim(txbgname.text) & " ' " else msgbox "请选择一个查询条件 ", vbexclamation + vbokonly, "查询失败 " exit sub end if '//当单选框选中时 if rsqbgong.state = adstateclosed then rsqbgong.open "bgsb ", dbcon, adopenkeyset, adlockoptimistic, adcmdtable end if if rsqbgong.state = adstateopen then rsqbgong.close end if if rsqbgong.state = adstateclosed then '//执行strsql中的 rsqbgong.open strsql, dbcon, adopenkeyset, adlockoptimistic, adcmdtext dgrecord.refresh '//刷新网格 set dgrecord.datasource = rsqbgong.datasource lblcount.caption = rsqbgong.recordcount '//将记录条数显示在标签上 txbgdanwei.text = empty '//请空文本框 txbgname.text = empty end if end sub private sub cmnreturn_click() unload me end sub private sub form_load() if rsqbgong.state = adstateopen then rsqbgong.close end if rsqbgong.open "bgsb ", dbcon, adopenkeyset, adlockpessimistic, adcmdtable if rsqbgong.recordcount > 0 then '//如果记录集中有记录 set dgrecord.datasource = rsqbgong.datasource '//设置网格的数据源 end if lblcount.caption = rsqbgong.recordcount end sub | | |
|