一直在試圖插入一條街,郊區和郵政編碼到表中,但不斷收到運行時錯誤「13」類型不匹配的MS Access VBA陣列
運行時錯誤「13」 類型不匹配
下面是代碼:
應該持有陣列需要聲明爲Variant,而不是作爲字符串Sub arrayData()
Dim CustomerNames() As Variant
Dim num As Long, dbs As Database, InsertReocrd As String
Dim CustomerID As Long, num1 As Long
Dim CustomerName As String
Dim Street As String, Suburb As String, Postcode As Integer
Set dbs = CurrentDb()
CustomerID = 0
For num1 = 0 To 50000
CustomerID = CustomerID + 1
CustomerNames = Array(...)
Street = Array("Short", "Lygon", "Flinders", "Elizabeth", "King") //ERROR OCURRS HERE
Suburb = Array("Sandringham", "Brighton", "St Kilda", "Melbourne", "Carlton") //ERROR OCURRS HERE
Postcode = Array("3165", "3298", "3145", "3144", "3000") //ERROR OCURRS HERE
num = Int((250 - 0 + 1) * Rnd + 0)
CustomerName = CustomerNames(num)
InsertRecord = "INSERT INTO CUSTOMER (CustomerID , CustomerName, StreetName, Suburb) VALUES (" & "'" & CustomerID & "'" & "," _
& "'" & CustomerName & "'" & "'" & StreetName & "'" & ")"
dbs.Execute InsertRecord
Debug.Print CustomerID, CustomerName, Street, Suburb
Next
End Sub
你可以告訴我你是什麼意思,因爲我拼寫時拼寫INSERT語句。 – TimboMan
下面是一個記錄集的例子:http://stackoverflow.com/a/36997654/3820271 – Andre