每當我去執行之後,就出現([Microsoft][ODBC Microsoft Access驅動程式]參數太少,以預期個數1)這問題???是否可幫我解決。
Dim R(1 To 20) As Integer
Dim i, j As Integer
Dim temp As Integer
Dim SQL As String
Dim str
'宣告一個connection類別的物件變數
Dim con As ADODB.Connection
'宣告一個recordset類別的物件變數
Dim rs As ADODB.Recordset
'隨機產生n個亂數
Randomize
For i = 1 To 20
R(i) = Int(Rnd() * 1001) + 1
Next
'將重複之亂數加1
For i = 2 To 20
For j = 1 To j - 1
If R(j) = R(i) Then
R(j) = R(j) + 1
End If
Next
Next
'利用氣泡排序法依遞增排序
For j = 1 To 19
For i = 1 To 19
If R(i) > R(i + 1) Then
temp = R(i)
R(i) = R(i + 1)
R(i + 1) = temp
End If
Next
Next
'顯示隨機抽取題號'
str = "丙檢試題.題號=" & R(1) & "or"
For i = 1 To 19
str = str & "丙檢試題.題號=" & R(i) & "or"
Next i
str = str & "丙檢試題.題號=" & R(20)
SQL = "SELECT 丙檢試題.題號, 丙檢試題.題目, 丙檢試題.選項一, 丙檢試題.選項二, 丙檢試題.選項三, 丙檢試題.選項四, 丙檢試題.難易度"
SQL = SQL & " From 丙檢試題 WHERE 丙檢試題.題號= str"
Adodc1.RecordSource = SQL
Adodc1.Refresh
'建立物件,並且指定給con物件變數
Set con = New ADODB.Connection
'利用ODBC開啟資料庫
con.Open "886440"
'建立物件,並且指定給rs物件變數
Set rs = New ADODB.Recordset
'設定ADO開啟資料庫的方法
rs.CursorLocation = adUseClient
rs.Open SQL, con, adOpenKeyset, adLockOptimistic
rs.Close
Set rs = Nothing
con.Close
End Sub