Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 25th, 2005, 09:22 AM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 314 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 31 m 3 sec
Reputation Power: 5
Send a message via Yahoo to wackyflik
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.

Reply With Quote
  #2  
Old May 25th, 2005, 09:29 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
Code:
SELECT DISTINCT [FieldName] FROM pelajar ORDER BY [FieldName]

While NOT .eof 
   combobox1.Item.Add(values here)
End While

Reply With Quote
  #3  
Old May 25th, 2005, 10:08 AM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 314 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 31 m 3 sec
Reputation Power: 5
Send a message via Yahoo to wackyflik
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.

Reply With Quote
  #4  
Old May 25th, 2005, 11:09 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 452
Quote:
Originally Posted by wackyflik
ur code doesnt work.

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

Reply With Quote
  #5  
Old May 25th, 2005, 08:49 PM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 314 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 31 m 3 sec
Reputation Power: 5
Send a message via Yahoo to wackyflik
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.

Reply With Quote
  #6  
Old May 25th, 2005, 08:52 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 22 h 23 m 39 sec
Reputation Power: 181
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

Reply With Quote
  #7  
Old May 25th, 2005, 09:00 PM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 314 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 31 m 3 sec
Reputation Power: 5
Send a message via Yahoo to wackyflik
Quote:
Originally Posted by Doug G
Have you inspected the variables with the debugger? Presumably rs.Fields("pel_wnegara").Value is NULL


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.

Reply With Quote
  #8  
Old May 25th, 2005, 11:49 PM
wackyflik's Avatar
wackyflik wackyflik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Malaysia
Posts: 314 wackyflik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 13 h 31 m 3 sec
Reputation Power: 5
Send a message via Yahoo to wackyflik
done!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > how to populate distinct values from ms access db into combo box???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT