VB6に問題があります。私はそれにいくつかのComboBoxオブジェクトを持つフォームを持っています。私は、パラメータとしてSQLクエリを取る関数を介してComboBoxesを設定したいと思う。コードは次のようになります"オブジェクト変数またはWithブロック変数が設定されていません" VB6のランタイムエラー
Private Function FillComboBoxFromMDB(ByVal sDBName As String, _
ByVal sSQL As String) As ComboBox
'/*
' * Execute SQL in MDB and fill the ComboBox with the results
' * Returns filled ComboBox
' */
Dim DB As Database
Dim DBRecordset As Recordset
On Error GoTo FillComboBoxFromMDB_ErrHandler
Set DB = OpenDatabase(sDBName, False, False)
If Not DB Is Nothing Then
Set DBRecordset = DB.OpenRecordset(sSQL)
If Not DBRecordset Is Nothing Then
If DBRecordset.RecordCount > 0 Then
Call FillComboBoxFromMDB.AddItem(DBRecordset.Fields(0).Value)
' ^^ This row gives the "Object variable or With block variable not set"
End If
Else
Call WriteLog("Unable to execute " & sSQL)
End If
DB.Close
Else
Call WriteLog("Unable to open " & sDBName)
End If
Exit Function
FillComboBoxFromMDB_ErrHandler:
Call WriteLog("FillComboBoxFromMDB() error: " & Err.Number & " " & Err.Description)
End Function
私はこのような関数を呼び出します。
Private Function Test()
' Fill the combobox
frmMyForm.cmbMyCombo = FillComboBoxFromMDB("Database.mdb", _
"SELECT MyTable.MyText FROM MyTable")
End Function
これは基本的に私が理解しているところですが、私はそれをオンラインで役に立つものは何も見つかりませんでした。 NewキーワードはVB.Netで動作するようには動作しません。関数が機能するようにFillComboBoxFromMDBコンボボックスをインスタンス化するにはどうすればよいですか?それも可能ですか?
ありがとうございます!
おめでとうございます! VB6の2つのエラーメッセージの1つに遭遇しました! (他の唯一のものは「メソッド '〜'はオブジェクト '〜'にありません」) –
「ActiveXエラー429」を忘れないでください:) – AakashM
これは、最も楽しいものの1つです。私はちょうど2000年からその機能を追加するためにそれらの遺産のプロジェクトを得るのが大好き... – Gert