私はこのコードを苦労して作成しましたが、それは動作しますが、数百回の繰り返しを経て遅くクラッシュします。私はデータベース検索の結果を示すマルチcoloumnリストボックスを持っています。私はそれらの結果を取って、コマンドボタンのクリックで "MailingListTemp"と呼ばれる一時テーブルに入れたいと思う。これを早くしてクラッシュや代替の方法にしない方法がありますか?最終的な結果は、リストをExcelにエクスポートすることです。リストボックスの検索結果をテーブルに送信
ありがとうございました。ここに私のコードです:
Private Sub AllToMailingListCommand_Click()
Dim i As Variant
Dim Item As Variant
Dim var0Search As Variant
Dim var1Search As Variant
Dim var2Search As Variant
Dim var3Search As Variant
Dim var4Search As Variant
Dim var5Search As Variant
Dim var6Search As Variant
Dim var7Search As Variant
Dim var8Search As Variant
Dim var9Search As Variant
Dim var10Search As Variant
Dim var11Search As Variant
Dim var12Search As Variant
Dim strX As String
Dim DValue As String
DValue = " "
DValue = Format(date, "mm/dd/yyyy")
Dim dbThisDatabase As DAO.Database
Dim rstMailingListTemp As DAO.Recordset
Set dbThisDatabase = CurrentDb
Set rstMailingListTemp = dbThisDatabase.OpenRecordset("MailingListTemp")
For i = 0 To Me.List0.ListCount
Me.List0.Selected(i) = True
For Each Item In List0.ItemsSelected
var0Search = List0.Column(0, Item)
var1Search = List0.Column(1, Item)
var2Search = List0.Column(4, Item)
var3Search = List0.Column(5, Item)
Next
var4Search = DLookup("[FirstName]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var5Search = DLookup("[LastName]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var6Search = DLookup("[Zip]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var7Search = DLookup("[Address1]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var8Search = DLookup("[Address2]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var9Search = DLookup("[Address3]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var10Search = DLookup("[Prefix]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var11Search = DLookup("[Suffix]", "[Master Marketing List]", "[MMLID] = " & var0Search)
var12Search = DLookup("[Title]", "[Master Marketing List]", "[MMLID] = " & var0Search)
rstMailingListTemp.AddNew
rstMailingListTemp("ID").value = var0Search
rstMailingListTemp("CompanyName").value = var1Search
rstMailingListTemp("City").value = var2Search
rstMailingListTemp("State").value = var3Search
rstMailingListTemp("FirstName").value = var4Search
rstMailingListTemp("LastName").value = var5Search
rstMailingListTemp("Zip").value = var6Search
rstMailingListTemp("Address1").value = var7Search
rstMailingListTemp("Address2").value = var8Search
rstMailingListTemp("Address3").value = var9Search
rstMailingListTemp("Prefix").value = var10Search
rstMailingListTemp("Suffix").value = var11Search
rstMailingListTemp("Title").value = var12Search
rstMailingListTemp.Update
Next i
End Sub
なぜサブフォームとしてリストボックスを使用していますか? –