Dim n,n1,n2,i,max,min As Integer
Dim Zy,T As String
Dim tb1,tb2 As Table
Dim r,r1,r2 as row
tb1 = Tables("地址")
tb2 = Tables("地址.用户")
tb1.Filter = "路名 is not null"
For Each k As Row in Tables("地址.用户").Rows
if k("状态") ="" then
if k("有效日期") >#1/1/2008# AndAlso K("有效插数") <>0 OrElse K("用户类别") = "全免户" then
k("状态")= "有效"
else k("状态")= "无效"
end if
end if
k("层") = k("生成房号").SubString(0,k("生成房号").Length - 2)
k("号") = k("生成房号").SubString(k("生成房号").Length - 2)
Next
r = tb1.current
for each r1 in tb2.rows
zy =zy & "|" & r1("生成房号")
Next
n1 = tb2.Compute("min(层)")
n2 = tb2.Compute("max(层)")
min = tb2.Compute("min(号)")
max = tb2.Compute("max(号)")
if n2 > n1 AndAlso n1 > 0 then
tb2.Redraw = False
For n = n1 to n2
For i = min to max
T = n & format(i,"00")
if Zy.IndexOf(T) = -1 then
r2 = tb2.addnew
r2("生成房号") = T
r2("房号") = T
r2("状态") ="无资料"
r2("路名") = r("路名")
r2("街名") = r("街名")
r2("号码") = r("号码")
r2("栋") = r("栋")
r2("小区") = r("小区")
r2("梯") = r("梯")
end if
Next
Next
tb2.Redraw = true
end if
这个代码是向子表增加记录,有点奇怪啊,第一次运行这段代码时,父表的当前记录(r = tb1.current)会自动向下移一条记录,(相应的会在当前行的下一条记录的子表增加了记录,)第二次以后运行这段代码就不会了,选择父表的记录,就会向那条记录的关联子表增加数据了,完全正常了。同一段代码,第一次运行代码和第二次运行代码都有点区别吗?是那里出问题了?