“模糊查询30个textbox其中不为空(条件数量不确定,即不为空的BOX数量不确定)的记录并全部写入表2” 想了个办法出来: Private Sub cmdFind_Click() '查找并写入 Dim Sql$, i% Set DB2 = OpenDatabase(ThisWorkbook.Path & "\pallet.mdb") Set RS2 = DB2.OpenRecordset("findyh", dbOpenDynaset) DB2.Execute "delete from findyh" Sql = "insert into findyh select * from yh where " For i = 1 To 28 If Controls("textbox" & i) <> "" Then Sql = Sql & RS2.Fields(i).Name & " like '*" & Controls("textbox" & i).Text & "*' and " End If Next Sql = Left(Sql, Len(Sql) - 4) DB2.Execute Sql RS2.Close: DB2.Close Set RS2 = Nothing: Set DB2 = Nothing Unload Me UserForm1.Show End Sub 事先在填写文本框时对应为: For i = 1 To 28 Me.Controls("textbox" & i).Text = IIf(IsNull(RS1.Fields(i)), "", RS1.Fields(i)) Next http://club.excelhome.net/dispbbs.asp?boardid=2&replyid=444973&id=160847&page=1&skin=0&Star=7 第64楼 |