を投入 -エクセルVBAオブジェクト必要なエラー私は、次のエラーを取得していますコンボボックス
実行時エラー「424」:オブジェクトは、ここで
を必要と私はエラーメッセージを取得していたコードです。エラーが表示された行は、と強調されている****Sub LoadDropdown_Click()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stDB As String, stSQL As String
Dim xlCalc As XlCalculation
Dim vaData As Variant
Dim k As Long
Set cnt = New ADODB.Connection
cnt.connectionString = Module1.GetConnectionString
stSQL = "EXEC dbo.GetData"
With cnt
.CursorLocation = adUseClient 'Necesary for creating disconnected recordset.
.Open stConn 'Open connection.
'Instantiate the Recordsetobject and execute the SQL-state.
Set rst = .Execute(stSQL)
End With
With rst
Set .ActiveConnection = Nothing 'Disconnect the recordset.
k = .Fields.Count
'Populate the array with the whole recordset.
vaData = .GetRows
End With
'Close the connection.
cnt.Close
'Manipulate the Listbox's properties and show the form.
With ComboBox21
.Clear ' **** the error comes at this line since ComboBox21 is empty ******
.BoundColumn = k
.List = Application.Transpose(vaData)
.ListIndex = -1
End With
Dim i As Integer
'Release objects from memory.
Set rst = Nothing
Set cnt = Nothing
End Sub
これらは私がveifiedているものです -
コンボボックスは、実際の優先順位と呼ばれる、シート1に存在します。 See this screenshot showing that Sheet1 contains a Combobox called ComboBox21
以下の機能は、LoadDropdown_ClickがSheet1にあります。 See this screenshot for details
このコードは、特定のマシンから実行しているときに機能します。以前はマシン上で動作していましたが、コードや環境を変更せずに突然このエラーが発生しています。
ComboBox21をSheet1.ComboBox21に変更しようとしましたが、コンパイルエラーが発生しました - メソッドまたはデータメンバーが見つかりません。
誰かが助けることができたら嬉しいです!
Sheet1.ComboBox21' –
は、このような状況で "オブジェクトが必要です" '試しは2つのことを示します:1)あなたは'オプションExplicit'を使用していない、そして2) 'ComboBox21 '明らかに範囲内ではないので、@ RobinMackenzieのように予選を試してみてください。また、すべてのモジュールの先頭に 'Option Explicit'を指定し、すべての変数を宣言してください。 –
また、コントロールの名前を 'PrioritySelection'または同様の意味を持つ名前に変更することを強くお勧めします。 'ComboBox21'は何も意味しません。 –