|
1.引用ADO
2.表中增加ID自动编号字段
3.新建模块
- Public Function gFieldName(ID As Long) As String
- Dim rs As New ADODB.Recordset
- Dim sSQL As String
- Dim tempStr As String
- Dim I As Long
- Dim Ws As Long
- sSQL = "SELECT 汇总数据.VSF余额, 汇总数据.W1, 汇总数据.W2, 汇总数据.W3, 汇总数据.W4, 汇总数据.W5, 汇总数据.W6," _
- & "汇总数据.W7, 汇总数据.W8, 汇总数据.W9, 汇总数据.W10, 汇总数据.W11, 汇总数据.W12 FROM 汇总数据 WHERE ID=" & ID
- rs.Open sSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
- For I = 1 To rs.Fields.Count - 1
- Ws = Ws + rs.Fields(I)
- Next
- If rs.Fields(0) - Ws < 0 Then
- For I = 1 To rs.Fields.Count - 1
- If rs.Fields(I) > 0 Then
- tempStr = rs.Fields(I).Name
- Exit For
- End If
-
- Next
- Else
- tempStr = "OK"
- End If
- gFieldName = tempStr
- rs.Close
- Set rs = Nothing
- End Function
复制代码 4.将下面的查询语句作为子窗体的窗体记录源
- SELECT gfieldname([id]) AS 缺料周数, 汇总数据.VSF余额, 汇总数据.W1, 汇总数据.W2, 汇总数据.W3, 汇总数据.W4, 汇总数据.W5, 汇总数据.W6, 汇总数据.W7, 汇总数据.W8, 汇总数据.W9, 汇总数据.W10, 汇总数据.W11, 汇总数据.W12
- FROM 汇总数据;
复制代码 5.注释掉你原来的代码
|
|