|
Hello, saya gune vee bee 6. Saya nak tau macam mana nak gune combo box pastuh ape yg kite pilih akan kluar kat textbox?
Sebagai contoh, byk2 nama makanan dalam list kat combo box and bile kite click salah satu nama makanan, nama tu akan appear kat textbox. Minta tolong ajar ye. ;D |
|
|
|
|
|
|
|
Consider this example.
Put one combo box and a text box in a form. Name the combo box Combo1 and the text box Text1.
Lepas tu, in the Form Load event, add the following:
Sub Form_Load
Combo1.Clear ' clears the combo box
Combo1.AddItem "Ayam goreng"
Combo1.AddItem "Daging masak merah"
Combo1.AddItem "Bistik ayam"
Combo1.AddItem "Kerabu mangga"
End Sub
Lepas tu, dalam event Click untuk Combo1, add the following:
(ataupun boleh guna event AfterUpdate / Change, saya tak pasti yg mana paling sesuai)
Sub Combo1_Click
Text1 = Combo1
End Sub
Pastu run form tu, jalan ke idak.
Semoga berjaya. |
|
|
|
|
|
|
|
Ouhh terima kasih byk2 shahnazz tapi saya amik data dari microsoft access, itu la masalah nye. |
|
|
|
|
|
|
|
Saya masih tak tau mcm mana nak listkan data yg ada kat access gune combobox pastuh bile clcik kluar kat textbox. |
|
|
|
|
|
|
|
wow, fast reply.
sama ada update List property kat combo box, atau programmatically use the AddItem method of the combo box.
untuk retrieve from access table, i can give you a simple script using ADO. call this subroutine (in the Form_Load event maybe) to update the list in your combo box.
- Sub UpdateComboBox()
- ' using ADO connection
- Dim cn As New ADODB.Connection
- cn.ConnectionString = "... what is your connection string? ..."
- cn.Open
- ' clear the list
- Combo1.Clear
-
- 'get values from table and populate the combo box
- Dim rs as new ADODB.Recordset
- rs.ActiveConnection = cn
- rs.Open "select nama_makanan from makanan"
- while not rs.eof
- Combo1.AddItem rs("nama_makanan")
- rs.movenext
- rs.close
- End Sub
Copy the Code
i think that should work. sorry tak larat nak verify OK ke idak, mengantuk sangat nih, hehe... |
|
|
|
|
|
|
|
Hmm kite dah try tapi takde apa terjadi pon. Camne ek? |
|
|
|
|
|
|
|
cuba paste your code kat sini |
|
|
|
|
|
|
|
Private Sub UpdateComboBox()
' using ADO connection
Dim cn As New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
cn.Open
' clear the list
Combo1.Clear
'get values from table and populate the combo box
Dim rs As New ADODB.Recordset
rs.ActiveConnection = cn
rs.Open "select Subject Code from Subjects"
While Not rs.EOF
Combo1.AddItem rs("Subject Code")
rs.MoveNext
rs.Close
End Sub
[ Last edited by Bremen at 16-10-2006 09:11 PM ] |
|
|
|
|
|
|
|
Private Sub UpdateComboBox()
' using ADO connection
Dim cn As New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
cn.Open
' clear the list
Combo1.Clear
'get values from table and populate the combo box
Dim rs As New ADODB.Recordset
rs.ActiveConnection = cn
rs.Open "select Subject Code from Subjects"
While Not rs.EOF
Combo1.AddItem rs("Subject Code")
debug.print "Subject code: " & rs("subject code")
rs.MoveNext
rs.Close
End Sub
Dalam Microsoft Access (atau apa-apa database pun), cuba elakkan guna nama field yang ada spaces.
Contoh yang sesuai:
- SubjectCode
- subject_code
Contoh yang tak sesuai:
- subject code (ambiguous and actually syntactically not correct for SQL statements)
The workaround for microsoft access is to put square braces on columns in SQL statements, macam ni:
Select [Subject Code] From Subjects (try amending that to your code and see if it works). But kaedah ni hanya berkesan pada Microsoft Access sahaja.
Just as a test, add the code in green colour to your existing coding, run, pastu tengok output / immediate window, ada tak any values keluar. Kalau tak, kena olah semula database.
Otherwise, logically your algorithm is OK. I assume you call the UpdateComboBox sub in the Form_Load event. |
|
|
|
|
|
|
|
Coding ni taruk kat form load atau combo box? |
|
|
|
|
|
|
|
dah dapat tapi combo box tuh cuma listkan 1st row saje, yg row lain dalam database tu takde plak dia listkan. |
|
|
|
|
|
|
|
While Not rs.EOF
Combo1.AddItem rs("Subject Code")
debug.print "Subject code: " & rs("subject code")
rs.MoveNext
Wend
rs.Close
tambah satu lagi line of code sepertimana yang ditunjukkan.
sorry tak perasan...
selamat mencuba |
|
|
|
|
|
|
|
tumpang tanya...
korang tau tak website yg ada contoh2 projek vb nih... aku nk wat rujukan la... |
|
|
|
|
|
|
|
Macam mana saya nak upload gambar dlm ni? Saya ade bende nak tanye. |
|
|
|
|
|
|
|
Originally posted by Bremen at 20-10-06 10:44 PM
Macam mana saya nak upload gambar dlm ni? Saya ade bende nak tanye.
upload gambar kat image shack
n watkan image tu thumbnail so xde la bsar n lama nak loading |
|
|
|
|
|
|
|
Listview dan datacombo
Hello semua, saya nak tau camne nak listkan kat listview ape yg saya pilih dari datacombo di atas? saya tak tau apa2 coding...kurang paham. Mintak tolong sape2 please :D
|
|
|
|
|
|
|
kayos_rayos This user has been deleted
|
Click kat Combo box
Private Sub Combobox1_Click()
''' letak kod kat sini...
End Sub
Application Developer
IT.BaseLogger
0123959774 |
|
|
|
|
|
|
| |
|