标题: 请问如何才能批量性的拆分数量呢? [打印本页] 作者: yanwei82123300 时间: 2013-1-7 15:40 标题: 请问如何才能批量性的拆分数量呢? 各位老师请问如何才能批量性的拆分数量呢?我现在有一个例子只能是一个参数,拆分一个数量,
例子:在窗体MO字段中输入“MO-137001”数据就会拆分到“表1"中
现在想将表“tblMO”中的已MO为条件批量性拆分到“表1"中.
请帮助看看,谢谢
tlbMO
MO:
MO-137001
MO-137002
MO-137003
MO-137004
MO-137005
MO-137006
MO-137007
MO-137008
MO-137009
MO-137010
MO-137011
MO-137012
MO-137013
MO-137014
MO-137015
MO-137016
MO-137017
MO-137018作者: Henry D. Sy 时间: 2013-1-7 15:43
什么意思?作者: Henry D. Sy 时间: 2013-1-7 15:46
能不能说说,你想根据什么来得到什么吗作者: yanwei82123300 时间: 2013-1-7 15:51
请见这个帖子http://www.office-cn.net/thread-116261-1-1.html作者: yanwei82123300 时间: 2013-1-7 15:51
做标签用作者: huangli0356 时间: 2013-1-7 16:01
你的标签是用报表形式体现吗? http://www.office-cn.net/thread-114999-1-1.html
希望对你有帮助作者: koutx 时间: 2013-1-8 10:14
如下改一下看是否你要的效果:
Private Sub Command4_Click()
On Error Resume Next
DoCmd.Close acTable, "表1"
Dim S As String
For i = 1 To Me.QTY
S = Format(i, "000")
DoCmd.RunSQL "INSERT INTO 表1 SELECT '" & S & "' AS 序号, '" & Me.ITEM & "' AS item, " & CInt(Me.QTY) & " AS qty, '" & Me.MO & "' AS mo"
Next i
DoCmd.OpenTable "表1"
End Sub 作者: koutx 时间: 2013-1-8 10:31
如要一次将表中所有记录全拆到表1中,则不需窗体,写一SUB模块在需要调用的地方CALL即可:
Sub 拆分()
On Error Resume Next
Dim S As String
Dim rst1 As adodb.Recordset
Dim str1 As String
str1 = "SELECT * FROM tblMO"
Set rst1 = New adodb.Recordset
rst1.Open str1, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rst1.RecordCount > 0 Then
rst1.MoveFirst
For i = 1 To rst1.RecordCount
For ii = 1 To rst1.Fields("QTY")
S = Format(ii, "000")
DoCmd.RunSQL "INSERT INTO 表1 SELECT '" & S & "' AS 序号, '" & rst1.Fields("ITEM") & "' AS item, " & rst1.Fields("QTY") & " AS qty, '" & rst1.Fields("MO") & "' AS mo"
Next
rst1.MoveNext
Next
End If
End Sub 作者: yanwei82123300 时间: 2013-1-8 12:55
koutx 老师谢谢您的帮助,但是还有一个小问题我将字段"desc”添加到语句中为何不执行呢?谢谢看看
DoCmd.RunSQL "INSERT INTO 表1 SELECT '" & S & "' AS 序号, '" & rst1.Fields("ITEM") & "' AS item, " & rst1.Fields("QTY") & " AS qty, '" & rst1.Fields("MO") & "' AS mo",'" & rst1.Fields("DESC") & "' AS desc"