كيفية مل cmbo box من قاعدة بيانات
الرجاء منكم ايها المبرمجين شرح هذا الكود خطوة خطوة
ومهمته هي مل cmbo box من قاعدة بيانات بس
اريد كيف استعمل هذا الكود اذا كان هناك قاعدة بيانات اسمها
project
والحقل المعني اسمة
cust_name
علما باني استعمل
vb & sql server
Ibrahim Eltayeb
Khartoum Sudan
Public Sub LoadBox(cboBox As Object, strTB, IDField, descField As
String)
On Error GoTo Errors
Dim rs As Recordset 'Declare a recordset
Dim sql As String 'Declare a string to hold the SQL statement
cboBox.Clear
sql = ""
sql = "SELECT " & IDField & ", " & descField & " FROM " & strTB
Set rs = db.OpenRecordset(sql, dbOpenForwardOnly)
With rs
Do Until .EOF 'Loop until the End of the recordset
cboBox.AddItem rs(descField)
cboBox.ItemData(cboBox.NewIndex) = rs(IDField)
.MoveNext
Loop
.Close
Debug.Print cboBox.Name & " was populated"
End With '(rs)
Set rs = Nothing 'Release the variable
Exit Sub
Errors: 'Error handler
If Err.Number <> 0 Then
MsgBox ("Error #: " & str(Err.Number) & Err.Description)
Exit Sub
End If
End Sub
