有两个窗体,一个是用来做查询条件的输入,另一个是通过根据查询条件来显示记录的用MSFlexgrid。第一个窗体:一个文本框为“业务员名字”、四个combo为时间限制。用到数据库的表:“订单”,数据库使用SQL
怎样才能够是第二个窗体显示的数据是根据第一个窗体的查询条件的出的数据?

解决方案 »

  1.   

    "select * from 订单 where 业务员=" & form1.text(combo1.text)
      

  2.   

    form2.msflexgrid.datasource=form1.adodc1
      

  3.   

    我试下看看,因为我还有用到combo,这四个combo这样的
    dbegindate = Format(CDate(Comboy(0) & Combom(0) & "-1"), "yymmdd")
    denddatetemp = DateAdd("d", -1, DateAdd("m", 1, DateSerial(CInt(Comboy(1)), CInt(Combom(1)), 1)))
    denddate = Format(dendatetemp, "yymmdd")
    还有我没有有用adodc1
    我用的是对象编程
      

  4.   

    将查询条件生成字符串,作为参数传给第二个窗体,在第二个窗体Load中进行查询,再显示到MSFlexgrid中
      

  5.   

    怎么样将两个combo的里面的内容组成时间
    像一个是2000另外一个03
    我要将它们组成2000-03-01
    因为我数据库的表的查询的的字段的格式是2000-03-01
    大家能够明白我说的吗?
    谢谢!
      

  6.   

    这样行吗?Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Form10.dbegindate & "'and shijian<='" & Form10.denddate & "'")
    dbegindate和denddate是我在Form10里面定义的两个参数。Dim denddate As String、Dim dbegindate As String
    但是运行时的错误是:未找到方法或数据成员!
    这两个在这个窗体里要不要再定义一次?
      

  7.   

    dim db as adodb.connection
    dim rec as adodb.recordersetCONNSTR = "Driver={SQL Server};Server=" & localhost & ";UID= ;PWD= ;DATABASE=" & 
    db.Open CONNSTR
    Set REC = New Recordset
          REC.Open ""select * from 订单 where 业务员=" & form1.text(combo1.text)
     ", db, adOpenStatic, adLockOptimistic
      

  8.   

    to(bingxuehuiren)我的form1中不止一个combo,就是说第一个combo表示年、第二个combo表示月。我要将这两个combo的内容组合起来,变成时间方式,然后查询时根据这个时间来查询!
      

  9.   

    to(冰雪惠儿):我那个表是里有个字段名叫“时间”其格式是为“yyyy-mm-dd”
    在查询窗体中的两个combo是先从表中显示其时间,将“yyyy”和“mm”分开。用Set mrc = cn.Execute("select distinct datepart(yy,shijian) from dingdan")
    然后在将这两个合起来再做查询条件。
    其实这个都是为了用户方便,如果不用combo的话,直接用个text就可以叫他们去输。但是我想那样的话用户用起来不方便。
    你能看的懂我讲的吗?我的qq是30924915
      

  10.   

    用以下语法
    select ... from .. where year(时间)=combo1.text and month(时间)=combo2.text然后将该查询字符串传给第二个窗体
      

  11.   

    写详细点吧
    Sqlstr="select ... from .. where year(时间)=" &combo1.text &" and month(时间)=" &combo2.text
      

  12.   

    不行就先用一个变量等于combo1+combo2吧?再用以上的查询语句,不可能不对的!
      

  13.   

    Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Form10.Text(Comboy(0).Text) & "'+ " - " '" & Form10.Text(Combom(0).Text) & "'and shijian<='" & Form10.Text(Comboy(1).Text) & "'+" - "'" & Form10.Text(Combom(1).Text) & "'")这句话行吗?运行时出现错误呀!
      

  14.   

    是一个字段,year(时间)是取出年份
    month(时间)是取出月份
      

  15.   

    to(微笑)是两个窗体呀,to(冰雪慧儿)我怎么样将那个变量在第二个窗体调用?
      

  16.   

    比如你有form1和form2在form2中调用前一个的combo1
    form1.combo1.text
      

  17.   

    设置一个模块级的变量将值赋给它后可直接访问
    或设置一个窗体模块级的全局变量,访问时用以下方法如在两个窗休中都用Sqlstr作为变量的话
    Sqlstr=form1.Sqlstr
      

  18.   

    Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Trim(Form10.Comboy(0).Text) & "'+ " - " '" & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & "'+" - "'" & Trim(Form10.Combom(1).Text) & "'")
    运行出现的错误提示:类型不匹配
      

  19.   

    我在表里的“时间”是varchar型的但是它有日了即有yyyy-mm-dd但是查询时只有yyyy-mm。跟这个有关系吗?
    搞的我好象头晕了
      

  20.   

    你的时间用combo组合起来是“YYYY-MM”不是“YYYY-MM-DD”所以类型不对
      

  21.   

    Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Trim(Form10.Comboy(0).Text) &  " - " & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & " - " & Trim(Form10.Combom(1).Text) & "'")
      

  22.   

    在最后加一个通配符试试:
    Set mrc = cn.Execute("select * from dingdan where shijian Like '" & Trim(Form10.Comboy(0).Text) &  " - " & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & " - " & Trim(Form10.Combom(1).Text) & "'%")
      

  23.   

    没注意,改一改:
    Set mrc = cn.Execute("select * from dingdan where shijian Like '" & Trim(Form10.Comboy(0).Text) &  " - " & Trim(Form10.Combom(0).Text) & "% "
      

  24.   

    能解释下吗?Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Trim(Form10.Comboy(0).Text) &  " - " & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & " - " & Trim(Form10.Combom(1).Text) & "'")
      

  25.   

    取值后,直接复制给第二窗体的网格,然后UNLOAD 第一窗体显示第二窗体!
      

  26.   

    我发现用这个Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Trim(Form10.Comboy(0).Text) &  " - " & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & " - " & Trim(Form10.Combom(1).Text) & "'")不能真正的按照输入的时间段查询了
      

  27.   

    为什么不能按照combo中的时间查询了,显示记录?
    百思不得其解
      

  28.   

    你的短横线两头都多了一个空格吧?重新改一改:
    Set mrc = cn.Execute("select * from dingdan where shijian>= '" & Trim(Form10.Comboy(0).Text) &  "-" & Trim(Form10.Combom(0).Text) & "'and shijian<='" & Trim(Form10.Comboy(1).Text) & "-" & Trim(Form10.Combom(1).Text) & "'")
      

  29.   

    生成的这些字符可预先设置出来看一看,如使用msgbox,看是否是你需要的。