你吧代码贴出来让大家看看,共同分析解决

解决方案 »

  1.   

    代码好长,我怕大家都要看晕了.Option Explicit
    Dim rs As Recordset
    Private Sub cmdExit_Click()
      Unload Me
    End SubPrivate Sub cmdQuery_Click()
      Call SetGrid
    End SubPrivate Sub Form_Load()
      Dim i As Integer
      Dim str As String
      
      For i = 0 To 10
        cboYear.AddItem i + 2000
        cboYear.ItemData(cboYear.NewIndex) = i + 2000
      Next
      cboMonth.AddItem "  "
      cboMonth.ItemData(cboMonth.NewIndex) = 0
      For i = 1 To 12
        cboMonth.AddItem i
        cboMonth.ItemData(cboMonth.NewIndex) = i
      Next
      cboDay.AddItem "  "
      cboDay.ItemData(cboDay.NewIndex) = 0
      For i = 1 To 31
        cboDay.AddItem i
        cboDay.ItemData(cboDay.NewIndex) = i
      Next
      i = Year(Now) - 2000
      cboYear.ListIndex = i
      cboMonth.ListIndex = Month(Now)
      cboDay.ListIndex = 0
      Call SetGrid
    End SubPrivate Sub Form_Resize()
      On Error Resume Next
      
      Shape1.Width = Me.ScaleWidth - 40
      Shape1.Height = Me.ScaleHeight - 1500
      cmdExit.Left = (Me.ScaleWidth - cmdExit.Width) / 2
      cmdExit.Top = Me.ScaleHeight - 600
      grd.Width = Shape1.Width - 200
      grd.Height = Shape1.Top + Shape1.Height - 100 - grd.Top
      lblTitle.Left = (Me.ScaleWidth - lblTitle.Width) / 2
      Shape2.Left = grd.Left
      Shape2.Top = grd.Top
      Shape2.Height = grd.Height
      Shape2.Width = grd.Width
    End SubPrivate Sub SetGrid()
      Dim str As String
      Dim i As Integer
      Dim dtemp As Date
      Dim rst As ADODB.Recordset
      
     str = "SHAPE {SELECT OrderDate,OrderId,  CustName, InDate FROM Orders Where OrderType = 0"
     If cboMonth.ListIndex = 0 Then
       cboDay.ListIndex = 0
       str = str & " and orderdate between #" & DateSerial(cboYear.ItemData(cboYear.ListIndex), 1, 1) & "# and #" & DateSerial(cboYear.ItemData(cboYear.ListIndex), 12, 31) & "#"
     Else
       If cboDay.ListIndex = 0 Then
         dtemp = DateSerial(cboYear.ItemData(cboYear.ListIndex), cboMonth.ItemData(cboMonth.ListIndex) + 1, 1) - 1
         str = str & " and orderdate between #" & DateSerial(cboYear.ItemData(cboYear.ListIndex), cboMonth.ItemData(cboMonth.ListIndex), 1) & "# and #" & dtemp & "#"
       Else
         str = str & " and orderdate=#" & DateSerial(cboYear.ItemData(cboYear.ListIndex), cboMonth.ItemData(cboMonth.ListIndex), cboDay.ItemData(cboDay.ListIndex)) & "#"
       End If
     End If
       
     str = str & " ORDER BY OrderDate desc} AS Command1 APPEND (( SHAPE {SELECT OrderId, ProductName, ProductType, PkgType, `Count`, Price, subtotal, ItemId FROM OrderDetailWithProduct}  AS Command2 APPEND ({SELECT HKdate, JinE, OrderItemID FROM hkmx}  AS Command3 RELATE 'ItemId' TO 'OrderItemID') AS Command3) AS Command2 RELATE 'OrderId' TO 'OrderId') AS Command2 "
     Set rs = New ADODB.Recordset
     rs.Open str, db, 1, 2
     If rs.EOF And rs.BOF Then
        grd.Clear
        grd.Visible = False
      Else
        With grd
          Set .DataSource = rs
          .ColHeader(2) = flexColHeaderOn
          .BandExpandable(1) = False
          .BandExpandable(0) = False
          .FormatString = " |^出库日期|<出库单号|<客户名称|^收款日期"
          .ColWidth(0, 0) = 300
          .ColWidth(1, 0) = 1000
          .ColWidth(2, 0) = 1200
          .ColWidth(3, 0) = 2500
          .ColWidth(4, 0) = 1000
          
          .ColWidth(0, 1) = 0
          .ColWidth(1, 1) = 1500
          .ColWidth(2, 1) = 1000
          .ColWidth(3, 1) = 1000
          .ColWidth(4, 1) = 1000
          .ColWidth(5, 1) = 1000
          .ColWidth(6, 1) = 1200
          .ColWidth(7, 1) = 0
          .ColHeaderCaption(1, 1) = "产品名称"
          .ColHeaderCaption(1, 2) = "规格"
          .ColHeaderCaption(1, 3) = "型号"
          .ColHeaderCaption(1, 4) = "数量"
          .ColHeaderCaption(1, 5) = "单价"
          .ColHeaderCaption(1, 6) = "小计"
           
          .ColAlignmentBand(2, 0) = 4
          .ColWidth(0, 2) = 1000
          .ColWidth(1, 2) = 1000
          .ColWidth(2, 2) = 0
          .ColHeaderCaption(2, 0) = "回款日期"
          .ColHeaderCaption(2, 1) = "回款金额"
          .Visible = True
        End With
      End If
      rs.Close
    End Sub