insert 另一表 select '001' 编号,表1.名稱,表2.價格 from 表1 inner join 表2 on 表1.编号=表2.编号 where 表1.编号=3
如果要复制[名称]、[价格]字段相等的记录的其它字段中的信息,可按下面给的方法。如果还是复制[名称]、[价格]这两个字段中的内容,是不是太愚昧了点。(恕我用词不敬)Dim rs As RecordsetPrivate Sub txt名称_AfterUpdate() procPaste end subPrivate Sub txt价格_AfterUpdate() procPaste end sub private sub procPaste() if txt名称<>"" and 价格<>"" and 其他字段1="" then Set rs = CurrentDb.OpenRecordset("select * from table1 a join table2 b" _ on a.编号=b.编号 where a.名称='" & txt名称 & "' and b.价格=" & txt价格 ) if rs.recordcount>0 then txt其它字段1=rs!其它字段1 txt其它字段2=rs!其它字段2 ... end if end if End Sub
select '001' 编号,表1.名稱,表2.價格 from 表1 inner join 表2 on 表1.编号=表2.编号 where 表1.编号=3
procPaste
end subPrivate Sub txt价格_AfterUpdate()
procPaste
end sub
private sub procPaste()
if txt名称<>"" and 价格<>"" and 其他字段1="" then
Set rs = CurrentDb.OpenRecordset("select * from table1 a join table2 b" _ on a.编号=b.编号 where a.名称='" & txt名称 & "' and b.价格=" & txt价格 )
if rs.recordcount>0 then
txt其它字段1=rs!其它字段1
txt其它字段2=rs!其它字段2
...
end if
end if
End Sub
谢谢你的回答,我问的确实是复制数据。是有点愚昧,不过学有所长,我也就无所谓了。
还有一个问题是
如果我要把数据放入到子窗体,而子窗体是个连续窗体怎么办?text1.text=rs.价格 [如¥12]
text1.text=rs.价格 [如¥13]
而在窗体上都是用同一个窗体表注的
insert into 表2(编号,价格) select '10',价格 from 表2 where 编号=3
表一:自动编号,名称编号,名称,备注。名称编号要求唯一
1 sc1 cp dell
2 sc2 sf micro
3 sc3 Cpu intel
表二:自动编号,名称编号,价格, 等级,厂家。名称编号可以重复,与表一名称编号相关联。
1 sc1 100 A a1
2 sc1 110 B a2
3 sc1 90 C a3
4 sc2 200 A b1
5 sc3 300 A d1
6 sc3 310 B a12张表是1对多的关系。现在我把2张表显示在窗体,以字段 [名称编号] 显示如下
主窗体
-----------------------------------------------
| 名称编号:sc1
| 名称:cp
| 备注:dell
|
|子窗体
| -----------------------------------------
| | 价格 等级 厂家
| | 100 A a1
| | 110 B a2
| | 90 C a3
| |----------------------------------------
|---------------------------------------------------
主窗体
-----------------------------------------------
| 名称编号: 没有
| 名称:cp
| 备注:dell
|
|子窗体
| -----------------------------------------
| | 价格 等级 厂家
| | 100 A a1
| | 110 B a2
| | 90 C a3
| |----------------------------------------
|---------------------------------------------------
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Open CurrentProject.Path & "\sc管理.mdb", "admin"
Set rst.ActiveConnection = cnn
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
str = "表一![名称编号]=" & "'" & strname & "'"
strSQL = "SELECT * FROM 表一 WHERE " & str
rst.Open strSQL
Me.名称编号 = rst.Fields(1).Value
Me.名称 = rst.Fields(2).Value
Me.备注 = rst.Fields(3).Value
Set rst = Nothing
Set cnn = Nothing我被这个困扰了,怎么办呀。不知道以上说明是否够详细。
& " select '" & 名称编号 & & "',价格, 等级,厂家 " _
& " from 表2 " _
& " where 名称编号='" & txtSID & "'"set me.子窗体名.Form.RecordsetClone.Requery
me.子窗体名.Form.RecordsetClone.Requery
嗯应该就是这种方法了,最关键的是在主窗体上放一个文本框,设名为txtSID,因为一开始我想先把这个主键空着不填数据,这是不行的,必须把主键确定下来。