|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
how to populate distinct values from ms access db into combo box???
how to populate distinct values from ms access db into combo box during Form_Load()??? the needed field is pel_wnegara. i have created a recordset named rsNegara at the Form_Load(). here is my code at the Form_Load()
Code:
Private Sub Form_Load() Set conAVB = New ADODB.Connection Set rsInfo = New ADODB.Recordset Set rsNegara = New ADODB.Recordset USP_DB = (App.Path & "\" & "ijazah tinggi.mdb") Set dbsUSP = OpenDatabase(USP_DB) conAVB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & USP_DB & ";Persist Security Info=False" conAVB.Open sql = "SELECT * FROM pelajar" With rsInfo .CursorLocation = adUseClient .Open sql, conAVB, adOpenDynamic, adLockOptimistic, adCmdText End With End Sub
__________________
teach and correct me if i am wrong... Last edited by wackyflik : May 25th, 2005 at 09:28 AM. |
|
#2
|
||||
|
||||
|
Code:
SELECT DISTINCT [FieldName] FROM pelajar ORDER BY [FieldName] While NOT .eof combobox1.Item.Add(values here) End While |
|
#3
|
||||
|
||||
|
ur code doesnt work. i have tried many codes. mostly quite same but still get the same error.
Run-time error '91': Object variable or With block variable not set this is my latest code written by arun banik. i just copied them and made some changes. i do not have any problem when runs his code but when i tried at my system, i got an error. Code:
Private Sub Form_Activate() rsGetNegara.Open "select distinct pel_wnegara from pelajar", con, adOpenDynamic, adLockOptimistic While Not rsGetNegara.EOF cmbNegara.AddItem rsGetNegara.Fields(0).Value rsGetNegara.MoveNext Wend End Sub error is at the bold statement. con is done in a module file. |
|
#4
|
||||
|
||||
|
Quote:
LOL, that's not my code causing the error, it's yours. Try this instead. Code:
Public Conn As ADODB.Connection
Public rs As ADODB.Recordset
Public strSql As String
Private Sub Form_Load()
Set Conn = New ADODB.Connection
Conn.ConnectionString = "Your ConnectionString"
Conn.Open
strSql = "SELECT DISTINCT pel_wnegara FROM pelajar ORDER BY Pel_wnegara"
Set rs = Conn.Execute(strSql)
If Not rs.EOF Then
Do Until rs.EOF
cboDepartment.AddItem (rs.Fields("pel_wnegara").Value)
rs.MoveNext
Loop
End If
Conn.Close
Set Conn = Nothing
End Sub
|
|
#5
|
||||
|
||||
|
ooopsss sorry. about ur code. i keep getting error. Invalid use of Null.
Code:
If Not rs.EOF Then
Do Until rs.EOF
cboDepartment.AddItem (rs.Fields("pel_wnegara").Value)
rs.MoveNext
Loop
End If
error at the bold statement. |
|
#6
|
|||
|
|||
|
Have you inspected the variables with the debugger? Presumably rs.Fields("pel_wnegara").Value is NULL
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#7
|
||||
|
||||
|
Quote:
how to do that??? i think i figured the problem. in her db at the pelajar table, there is a field named pel_ID and datatype is AutoNumber. and the record (1st row) started with no 18. |
|
#8
|
||||
|
||||
|
done!
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > how to populate distinct values from ms access db into combo box??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|